Extending Alfred.app with Applescript
Posted by Ricardo Martins on
EDIT: This post has been obsoleted by Alfred 0.6.1. :)
Lately, I’ve been using Alfred.app as my application launcher. I used to use Quicksilver, the grandfather of OSX app launchers but changed to Google Quick Search Box, since Quicksilver had some problems (namely with Snow Leopard and Spaces). However, Google QSB proved to be a little too slow for my taste, and Alfred showed up in Hacker News, so I gave it a shot. Couldn’t have been happier with my choice, even though it’s still in an early stage of development.
I still missed in Alfred something Google QSB had: easily accessible system actions, like sleep, shut down, restart and lock screen. I like to avoid using the mouse whenever I can.
This wasn’t a problem. I took a look at the applescript Google QSB uses internally1 and created standalone apps based on each action, using Google QSB’s icons2.
I’m quite pleased with the result, since I got my beloved actions back and Alfred.app is still snappy.
Sleep

tell application "System Events" to sleep
Shutdown

tell application "System Events" to shut down
Restart

tell application "System Events" to restart
Lock Screen

do shell script "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend > /dev/null"
1 /Applications/Quick Search Box.app/Contents/PlugIns/System.hgs/Contents/Resources/Scripts/main.scpt
2 /Applications/Quick Search Box.app/Contents/PlugIns/System.hgs/Contents/Resources/