Create global shortcut to run command line applications
Applescript it:
do shell script "ls ~/Desktop"
Add what you want there, then you can run the Applescript via a global hot key application. I would recommend Spark
Oh, and I don't know about assigning an shortcut through System Preferences
Without knowing the specifics of what you are looking for, I'd suggest creating a new Service through Automator. Services can be bound to keystroke triggers, and can execute shell scripts (among other things).
To set up the keyboard shortcut, go to System Preferences -> Keyboard -> Shortcuts -> Services, select the service you just saved, and then click the "Add Shortcut" button.
I tried all those options, but they're too complex and unreliable or really expensive. So i ended up writing my own solution (open-source and free).
iCanHazShortcut
It can't do much right now, but that's a start. Feel free to contribute by adding feature requests and suggestions.
FastScripts includes all scripts in ~/Library/Scripts/, so you don't have to add files manually. It also supports application-specific scripts.
Other applications that can be used to assign shortcuts for running scripts:
- Alfred
- Apptivate
- BetterTouchTool
- Butler
- Cockpit
- Controller Mate
- iKey
- Keyboard Maestro
- NuKit (only AppleScript)
- QuicKeys
- Quicksilver
- Shortcuts (only AppleScript)
- Spark
- ThisService
You can also create an Automator service:
- Open Automator and choose the Service template
- Add a Run Shell Script or Run AppleScript action
- Check that the input type and application scope are correct
- Paste the script and save the service
- Assign a shortcut in the Keyboard preference pane
There's a bug in 10.7 and 10.8 where the shortcuts for services don't always work until the services menu has been shown from the menu bar. Shortcuts for services don't work when the frontmost application doesn't have a menu bar or a services menu. There's also a short delay before services are run.
Quicksilver can be used to bind hotkeys to actions.
If you find yourself doing something frequently, you can speed up the task even more by assigning a “trigger” to it. Triggers can be activated by keyboard shortcuts or mouse movements
If it's a Unix command or shell script you want to execute, this Stackoverflow post gives some more information on using Quicksilver's "Terminal module".