Quick Cursor Replacement

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.

Recently, TJ Louma at MacSories, Dr. Drang, and several others created replacements for QuickCursor using Keyboard Maestro.

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:

 1 if (( $+commands[bbedit] ))
 2 then
 3         ## We found the command line bbedit tool
 4     CL_BBEDIT='yes'
 5 else
 6         ## We did NOT find the command line bbedit tool
 7     CL_BBEDIT='no'
 8 fi
 9 
10 if (( $+commands[subl] ))
11 then
12         ## We found the command line subl tool
13     CL_SUBL='yes'
14 else
15         ## We did NOT find the command line subl tool
16     CL_SUBL='no'
17 fi
18 
19 if [[ "$CL_BBEDIT" = "yes" && "$APP:l" == "bbedit" ]]
20 then
21         ## IFF the user wants to use BBEdit and they have the bbedit
22         ## command line tool installed, then we will use the bbedit tool
23 
24         ## if BBEdit is not running, launch it
25     pgrep -xq BBEdit || (open -a BBEdit && sleep 3)
26 
27         ## We will try to open the app with the bbedit command,
28         ## but if it fails we will open TextEdit
29     bbedit \
30         --language 'Markdown' \
31         --create-unix \
32         --new-window \
33         --resume \
34         --wait \
35         -- "$FILE" \
36      || open -n -e -W "$FILE"
37 # else if app is Sublime Text
38 elif [[ "$CL_SUBL" = "yes" && "$APP:l" == "sublime text" ]] 
39 then
40         ## IFF the user wants to use Sublime Text and they have the subl
41         ## command line tool installed, then we will use the subl tool
42 
43         ## if Sublime Text is not running, launch it
44     pgrep -xq "Sublime Text" || (open -a "Sublime Text" && sleep 3)
45 
46         ## We will try to open the app with the subl command,
47         ## but if it fails we will open TextEdit
48     subl \
49         --new-window \
50         --wait \
51         -- "$FILE" \
52      || open -n -e -W "$FILE"
53 
54 else
55         ## if we get here, either the app is NOT BBEdit or Sublime Text
56         ## or they do not have the `bbedit`/`subl` tool installed
57 
58         ## We will try to open the file in the requested app
59         ## but if the open command fails for some reason,
60         ## we will open TextEdit
61 
62     open -a "$APP" -n -W "$FILE" || open -n -e -W "$FILE"
63 
64 fi # if app is BBEdit or Sublime