Skip to content

Instantly share code, notes, and snippets.

@scriptingosx

scriptingosx/shellcheck

Last active Jan 13, 2017
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@scriptingosx scriptingosx commented Sep 30, 2016

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