【问题标题】:In AppleScript and BBEdit how can you check links?在 AppleScript 和 BBEdit 中如何检查链接?
【发布时间】:2017-04-22 12:40:59
【问题描述】:

在 BBEdit 中,Markup -> Check -> Document Links 快捷方式 cmd+control+k 下的命令可以检查所有链接。当我查看BBEdit > HTML Scripting -> check links 下的字典时,它显示:

但是当我尝试使用以下项目编写脚本时:

set theResult to check links of active document of project window 1

当我尝试根据以下文件名进行检查时,我收到错误 item

set foobar to (name of active document of project window 1) as string
set theResult to check links of foobar

如果我尝试,我仍然会遇到同样的错误:

set projectPath to file of project document 1
set theResult to check links of projectPath

我收到了{} 的回复。认为这是不添加 with show results 的问题,我将其更改为:

set theResult to check links of projectPath with show results

但我得到了activate的返回

当我通过 Google 搜索时,我无法找到一个解决方案,即是否可以返回一个布尔值,即 HTML 文件中的链接在通过内容编写脚本时是否有效。所以我的问题是,我怎样才能让 AppleScript 告诉我链接在 BBEdit 中使用check links 是有效的?

【问题讨论】:

    标签: html file applescript bbedit


    【解决方案1】:

    从活动文档的文件中检查链接:

    tell application "BBEdit"
        set theFilePathOfFrontProject to file of text document 1 -- get the path of the selected file in the front project window
        set theResult to (check links of theFilePathOfFrontProject) is {}
        if theResult  then
            display dialog "All links appear to be valid"
        else
            display dialog "Some links appear to be not valid"
        end if
    end tell
    

    信息:

    set projectPath to file of project document 1,此命令返回项目的路径(检查此文件上的链接将始终返回一个空列表),路径将是file "fullpath:someName.bbprojectd",不是所选HTML的路径strong> 项目中的文件。

    获取项目所有文件的路径:set allFilePaths to project collections of project document 1 -- list of paths

    【讨论】:

    • 是的,我最终使用了类似的东西,但它花了更多的行,但最后它是一个条件检查列表是否为空,但解决方案加 1
    【解决方案2】:

    我相信这在我上次使用它时有效,我在移动设备上即将登机,所以语法可能已经含糊不清。

    set theFile to ((path to documents folder) as string) & "test.html"
    set theResult to check links of file theFile
    

    要使用系统事件来按键,您可以使用单独的 tell 块,或创建类似的处理程序。

    on checkLinks()
        tell application "System Events"
            keystroke "k" using {command down, control down}
        end tell
    end checkLinks
    

    然后像往常一样调用处理程序

    my checkLinks()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多