Check Syntax in BBEdit

Summary: Validates the HTML syntax of the the current page using BBEdit.
Requires: Safari, BBEdit
Suggested Key Binding: Control-Command-Y
Install Location: ~/Library/Scripts/Applications/Safari/
Last Modified: 2026-05-29

Description

Validates the HTML syntax of the the current page, showing any errors in a BBEdit results browser. If there are no errors, no window is shown.

Installation Instructions · Download in Compiled Format · Download in Text Format

Script

tell application "Safari"
    tell
document of window 1
        set
_html to source
    end tell
end tell

-- Only works outside of BBEdit's `tell` block
set
_folderPath to (path to temporary items folder)'s POSIX path
set
_filePath to _folderPath & "SafariSyntaxCheck.html"
set
_file to POSIX file _filePath

tell
application "BBEdit"
    set
_document to make new text document with properties {text:_html}
    
save _document to _file
    
-- Doesn't show a window if no errors
    set
_errors to check syntax _file with show results
    
-- Currently, it can't check remote links or links on the same site when not stored locally
    
-- set _errors to _errors & (check links _file with show results)
    
close _document's window
    if
_errors is not {} then activate
end tell