A while back I was searching for a way to launch applications on selected file(s) in the Mac OS X Finder using Hotkeys. This is different from launching the default application (Cmd-Down, Cmd-O or Double-Click the mouse) for a file as I sometimes want to launch different applications on the same file types - like a 'Right Click-Open With' using a mouse, or dragging a file onto an application in the dock or in the applications folder - but with fewer clicks and (more importantly for me) without using the mouse.

For example, I want the currently selected file(s) in the finder to be opened with TextMate when I hit Shift-Cmd-T, to be opened with 0xED when I hit Shift-Cmd-X and to be opened in VLC when I hit Shift-Cmd-V. I have managed to get this working and find this to be a great time saver, so I thought I'd share it.

It starts with a great free tool called Spark, which takes you halfway there. To get all the way there you need to add in a little AppleScript.

Open, change the context from All Applications Hotkeys (on the top) to Finder HotKey (you may need to add Finder as an application in the left pane first).

Finder app in Spark

Select the Finder application in the left pane and then double-click the AppleScript hotkey group. Now choose a hotkey (I went with Shift-Cmd-T), add a name and then insert this script (courtesy of Peter N Lewis):

tell application "Finder" to set finderfiles to selection as list  
set finderaliases to {}  
repeat with i in finderfiles  
  set a to i as alias  
  set finderaliases to finderaliases & a  
end repeat  
tell application "TextMate"  
  open finderaliases  
end tell

Entering script into Spark

Ensure that the Spark daemon is running (the status is shown on the main Spark application pane). You can now close the Spark application and only need to open it if you want to add or change shortcuts.

Now, whenever you push Shift-Cmd-T in the finder it will open the selected file or files or folder in TextMate. Nice :)

Repeat the above process to add other shortcuts, changing the application name as appropriate.


Another script I've been using is to go to a specific folder in Finder. I've setup hotkeys for the folders I visit a lot. The script is:

property the_path : "/path/to/folder/"  
set the_folder to (POSIX file the_path) as alias  
tell application "Finder"  
  if window 1 exists then  
    set target of window 1 to the_folder  
    reveal the_folder  
  end if  
end tell


Posted Thu 27 Jan 2011 by Michael Patricios , updated Wed 30 Jan 2013

Tag: Mac OS X

Post a comment