Clean-Up Macro

Most applications on the Mac allow you to hide all other applications. That’s a nice way to pretend that your workspace is clean, but it’s an illusion. I was thinking the other day that what I really want is something like a “Quit All Others” global hot key.

But, wait…

What I really want is a “Quit All Except for the Applications I Use All Of The Time” hot key.

And then there was the magic of Keyboard Maestro (KM) and AppleScript. KM is really just a conduit for triggering the AppleScript. I initially tried to build it in KM only but there is no conditional flow or testing actions available. Since it’s all AppleScript, it could easily be done with FastScripts too.

In KM simply setup a macro that is triggered by a custom key combination (shift-CMD-Q for me). The only action in the macro is to execute an AppleScript.

KM Macro Setup

The AppleScript (see end of this post) simply runs through and quits all applications that are not in the white list of the script. It also leaves the frontmost application running since I assume that’s the application that is in use. I use this macro in conjunction with a couple other tricks for a nice clean and easy to navigate environment.

[cc lang=“applescript”] tell application “System Events” to set the visible of every process to true on GetCurrentApp() tell application “System Events” set _app to item 1 of (every process whose frontmost is true) return name of _app end tell end GetCurrentApp try tell application “Finder” set process_list to the name of every process whose visible is true end tell set _currentApp to GetCurrentApp() set white_list to {“Finder”, “OmniFocus”, “BusyCal”, “nvAlt”, “LaunchBar”, “Keyboard Maestro”, “iTunes”, “Mail”, _currentApp} repeat with i from 1 to (number of items in process_list) set this_process to item i of the process_list if this_process is not in white_list then tell application this_process quit end tell end if end repeat on error tell the current application to display dialog “An error has occurred!” & return & “This script will now quit” buttons {“Quit”} default button 1 with icon 0 end try [/cc]

References

1. http://codesnippets.joyent.com/posts/show/1124

2. http://stackoverflow.com/questions/495323/quit-all-applications-using-applescript

3. http://vanderbrew.com/blog/2010/02/15/get-current-application-with-applescript/