Skip to content

Instantly share code, notes, and snippets.

@scriptingosx
Last active January 13, 2017 19:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptingosx/0573cc4a3eb5b303db71 to your computer and use it in GitHub Desktop.
Save scriptingosx/0573cc4a3eb5b303db71 to your computer and use it in GitHub Desktop.
check frontmost BBEdit window with spellcheck http://shellcheck.net
tell application "BBEdit"
if not (exists text document 1) then
return
end if
if source language of text document 1 is not "UNIX Shell Script" then
set thename to name of text document 1
display dialog "Document '" & thename & "' does not seem to be a shell script!"
return
end if
set theCode to text of text document 1
end tell
-- escape some crticial characters
set theCode to replace_chars(theCode, "\\", "\\\\")
set theCode to replace_chars(theCode, quote, "\"")
set theCode to replace_chars(theCode, "'", "\\'")
set theCode to replace_chars(theCode, "\n", "\\n")
tell application "Safari"
open location "http://shellcheck.net"
delay 1
do JavaScript "document.getElementById('code').value = '" & theCode & "';" in document 1
do JavaScript "transfer('#code', '#console')" in document 1
end tell
-- from the ever useful http://macosxautomation.com/applescript/sbrt/sbrt-06.html
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
@scriptingosx
Copy link
Author

Note that Safari now needs to enable to 'Allow JavaScript from AppleEvents' in the Develop menu for this script to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment