Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 Lawson Feb 23 '12 at 5:34

5 Answers 5

up vote 5 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
2  
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 Lawson Feb 19 '12 at 13:05
    
Also, AppleScript and Automator are part of OS X. –  Daniel Lawson Dec 11 '12 at 17:53
    
Thanks for the hint pointing me to Spark - seems to be exactly what I was searching for! –  Florian Loch Nov 18 at 8:16

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

It appears as though this was available in 10.6, (see http://hints.macworld.com/article.php?story=20090903085255430) 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

 
discard

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.