Tuesday, January 06, 2009

Launch Mac application / AppleScript by keyboard

In the comments to my recent post about full keyboard access to Mac OS X GUI controls “christian” asks about a way to open a new Finder window regardless of the front application. I understand his need, on Windows you just hit Windows+E anywhere and get a new Explorer window.

So far I have worked around this when I needed a Finder window by first hitting F19 which I bound to Exposé’s Show Desktop option and then clicking on the desktop. This enabled the finder and allows the Cmd-N hotkey to work.

However being able to just bring up a new Finder window from anywhere would of course be preferable. I first tried through the keyboard system preferences, however even though you can bind new keyboard shortcuts to any menu item by name. Because the application you target usually needs to focused this would not be of much help. There is a “Any application” setting, but this seems to work for a few people if any. I have not managed to get it right.

In Apple’s AppleScript documentation there is an example of how to bring up a Finder window with specific settings (like Column, List or Icon View, the initially displayed folder etc.) that goes like this:

tell the application "Finder"
	set w to make Finder window to home
	set current view of w to column view
	set toolbar visible of w to true
	set sidebar width of w to 0
end tell

On the net I found a nice little application called “Spark”. It provides a working way to define system wide keyboard shortcuts. Among other things like simply launching an app you can also execute AppleScripts. So I just defined Cmd-Shift-E – similar to Windows-E – to run the aforementioned script.

Picture 6

When you first start Spark it allows you to enable it on logon, so it is immediately available even after a reboot. I have not yet tried what happens if an application defines a shortcut for itself, so maybe there will need to be some tweaking.


christian said...

Thanks a lot Daniel! It's a perfec solution for me!

Dave. said...

Very nice! I didn't know about Spark!

In regards to keyboard shortcuts, have you tried Quicksilver? It lets you launch applications, find and manipulate data, browse the filesystem, control apps, etc. with just the keyboard. I know it's a must-have app for plenty of mac users out there, myself included.

dz0004455 said...

Thanks SO much. this was exactly what I was looking for. I think that this program needs to get more publicity.

Anonymous said...

Outsanding. Having just moved from Windows I was looking for exactly how to mimick Windows-E on a MAC. I have it working thanks to this post.