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

In AppleScript and BBEdit how can you check links?

在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

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

set theResult to check links of projectPath with show results

但我得到 return 的 activate

当我搜索 Google 时,我无法找到关于是否可以 return 布尔值的解决方案,以判断 HTML 文件中的链接在编写脚本时是否有效通过内容。所以我的问题是,如何让 AppleScript 告诉我链接在 BBEdit 中有效 check links?

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

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

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

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,此命令 return 项目的路径(检查此文件上的链接将始终 return 一个空列表),路径将为 file "fullpath:someName.bbprojectd" , 不是选中的HTML文件在工程中的路径

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