A long(-ish) time back Jesse Grosjean of HogBay Software created a wonderful little app called QuickCursor that let you open text from any application (or text field on a webpage) in your preferred text editor. Thanks to Apple’s sandboxing rules, QuickCursor stopped working, and I forgot about it.
I really liked QuickCursor, so I first tried Dr. Drang’s implementation and I couldn’t get it to work right for me, so I moved over to TJ’s and started poking around on it. At first, it didn’t work right with Sublime Text, so I updated the ZSH scripting to make use of Sublime’s
subl command line tool if you set the macro to use Sublime.
You can see my fork over on GitHub, but the relevant part is I replaced TJ’s BBEdit specific code with:
if (( $+commands[bbedit] )) then ## We found the command line bbedit tool CL_BBEDIT='yes' else ## We did NOT find the command line bbedit tool CL_BBEDIT='no' fi if (( $+commands[subl] )) then ## We found the command line subl tool CL_SUBL='yes' else ## We did NOT find the command line subl tool CL_SUBL='no' fi if [[ "$CL_BBEDIT" = "yes" && "$APP:l" == "bbedit" ]] then ## IFF the user wants to use BBEdit and they have the bbedit ## command line tool installed, then we will use the bbedit tool ## if BBEdit is not running, launch it pgrep -xq BBEdit || (open -a BBEdit && sleep 3) ## We will try to open the app with the bbedit command, ## but if it fails we will open TextEdit bbedit \ --language 'Markdown' \ --create-unix \ --new-window \ --resume \ --wait \ -- "$FILE" \ || open -n -e -W "$FILE" # else if app is Sublime Text elif [[ "$CL_SUBL" = "yes" && "$APP:l" == "sublime text" ]] then ## IFF the user wants to use Sublime Text and they have the subl ## command line tool installed, then we will use the subl tool ## if Sublime Text is not running, launch it pgrep -xq "Sublime Text" || (open -a "Sublime Text" && sleep 3) ## We will try to open the app with the subl command, ## but if it fails we will open TextEdit subl \ --new-window \ --wait \ -- "$FILE" \ || open -n -e -W "$FILE" else ## if we get here, either the app is NOT BBEdit or Sublime Text ## or they do not have the `bbedit`/`subl` tool installed ## We will try to open the file in the requested app ## but if the open command fails for some reason, ## we will open TextEdit open -a "$APP" -n -W "$FILE" || open -n -e -W "$FILE" fi # if app is BBEdit or Sublime