在AppleScript和BBEdit中如何查看链接?

时间:2017-04-11 02:05:55

标签: html file applescript bbedit

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

enter image description here

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

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文件中的链接有效。所以我的问题是,如何通过check links让AppleScript告诉我BBEdit中的链接是否有效?

2 个答案:

答案 0 :(得分:1)

我相信这在上次我使用它时起作用了,我正在移动即将登机,所以语法可能已经笨拙。

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()

答案 1 :(得分: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 文件。

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