2

In BBEdit there is the command under Markup -> Check -> Document Links shortcut cmd+control+k that checks all links. When I look at the dictionary under BBEdit > HTML Scripting -> check links it shows:

enter image description here

but when I try to script against a project with:

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

I get an Error of item, when I try to check based on the filename with:

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

I still get the same error, if I try:

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

I get a returned of {}. Thinking it was an issue with not adding with show results I changed it to:

set theResult to check links of projectPath with show results

but I get a return of activate

When I search through Google I'm unable to find a solution on if it's possible to return a boolean on wether the links in the HTML file are valid when scripting through the content. So my question is, how can I get AppleScript to tell me the links are valid in BBEdit with check links?

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

2 Answers2

1

I believe this worked last time I used it, I'm on mobile about to board a flight so syntax may have gotten mumbled.

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

To use system events to press keys, you could use a separate tell block, or create a handler like so.

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

then call the handler as usual

my checkLinks()
1

To check the links from the file of the active document:

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

Informations :

set projectPath to file of project document 1, this command return the path of the project (check links on this file will always return an empty list), the path will be file "fullpath:someName.bbprojectd", it's not the path of the selected HTML file in the project.

To get path of all files of the project : set allFilePaths to project collections of project document 1 -- list of paths

jackjr300
  • 7,111
  • 2
  • 15
  • 25