Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What steps do I need to run a command line program via a global shortcut?

I setup Automator to create a new Run Shell Script and tried to assign a shortcut in System Preferences -> Keyboard -> Keyboard Shortcuts, but nothing happened.

share|improve this question
My question is different. I don't want a terminal window to open up at all. – z-buffer Feb 23 '12 at 5:31
If you don't want a Terminal window to open at all, you are asking the same thing as the linked post. – Daniel Feb 23 '12 at 5:34
up vote 6 down vote accepted

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

share|improve this answer
Bingo. Odd this functionality isn't already built into OSX. Thanks so much! – Adam Flott Sep 3 '11 at 21:30
@Adam Yeah, it is a little odd. – daviesgeek Sep 3 '11 at 22:36
Except that it is built into OS X through Automator Services, @AdamFlott, it's just that the answer you accepted doesn't use that method. – Daniel Feb 19 '12 at 13:05
Also, AppleScript and Automator are part of OS X. – Daniel Dec 11 '12 at 17:53
-1 for using 3rd parties without any good reasoning. – cregox Aug 27 '15 at 22:56

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). enter image description here

share|improve this answer

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:

You can also create an Automator service:

  1. Open Automator and choose the Service template
  2. Add a Run Shell Script or Run AppleScript action
  3. Check that the input type and application scope are correct
  4. Paste the script and save the service
  5. 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.

share|improve this answer
plus one for mentioning other apps that do it as well. I almost went to install spark when I already used QuickSilver. I didnt know it had that option. – Marlon Dec 9 '11 at 7:23
also, the section in the "Keyboard preferences" pane to add a shortcut will be under the "Services" section, if using the Automator approach. – Brad Parks Apr 8 '14 at 16:34

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".

share|improve this answer

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).


It can't do much right now, but that's a start. Feel free to contribute by adding feature requests and suggestions.

share|improve this answer

It appears as though this was available in 10.6, (see but something broke in 10.7.2 (and possibly earlier 10.7)

I have found though that the Services keyboard shortcut is honoured when System Preferences is at the forefront, but not in any other application, including Finder.

However, the earlier suggestion to use Spark worked perfectly in lion, except that I couldn't use Ctrl in my keyboard shortcut. (not a showstopper!)

share|improve this answer
only when the application menu is in focus. If you click the desktop and tried the shortcut it doesnt work. click on the menu for finder and then try it and it works. I have a service for Terminal that has a shortcut and shows up on all apps...but it doesnt work if I'm not inside an app and even then the menu needs to have focus. – Marlon Dec 9 '11 at 7:19
@Lri even after loggin out and back in, restarted the machine, etc. It still doesnt work unless I do as I described above. Setting it in Quicksilver works though. I would like to know how come QuickSilver can catch those "global" shortcuts and not the OS. – Marlon Dec 9 '11 at 19:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.