Bind a key to a commandline command in Mac OS X?
Posted
by Stefan Lasiewski
on Super User
See other posts from Super User
or by Stefan Lasiewski
Published on 2010-06-17T23:03:59Z
Indexed on
2010/06/18
1:13 UTC
Read the original article
Hit count: 361
I have a Mac Powerbook running Leopard (10.5.8).
Does Leopard provide an easy way to bind keys to commands which are typically run on the commandline?
For example, I can open up Terminal.app and run the command
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine
which will activate the screensaver and lock my screen. What if I want to bind 'Apple-key L' to this command and execute this globally, regardless of which application is in use at the moment? Can I do this, or can I only run ScreenSaverEngine
from a Terminal window?
I tried to set up global keyboard shortcuts, but it seems that this won't allow me to bind a key to an arbitrary shell command:
Note: You can create keyboard shortcuts only for existing menu commands. You cannot define keyboard shortcuts for general purpose tasks such as opening an application or switching between applications.
I tried to set up a application keyboard shortcut, but commands like ScreenSaverEngine
don't seem to be an application.
Note that this Screensaver/Lock screen is just one example. I have come across other nifty commands which I might want to bind to a key-combination as well. I can do this in Gnome and Windows (with varying success). How about with Leopard?
Should I be looking at doing this with AppleScript? (I haven't used that since the Hypercard days ...)
© Super User or respective owner