Give Any Terminal Script A Global Short Cut 0

Tutorial

Share
Give Any Terminal Script A Global Short Cut

Hey

Over the past two weeks I have mentioned many times about making a Terminal script into a Service. This post is going to be a round up of some of the small quirks I have found and worked around. You can use this post as a may of booking this method if you forget how to do this in the future. In essence it will take any Terminal Bash script which you have made and would normally run in Terminal and apply a short cut. I’m finding this more and more useful as time goes on. I have a small growing list of scripts that I run on a daily basis.

Before I start there are two books I would like to point out on Amazon which have similar sort of articles. To a certain extent they take this concept a bit further. They are Automator for Mac Snow Leopard, which is a guide for Automator. A more general guide which features a more general tutorials is Snow Leopard, The Missing Manual.

If you have read my earlier posts the process is rather simple. We are going to create an Automator work flow which is designed to run as a Service from the Application > Services menu. We can then, through System Preferences, add a short cut. This short cut will allow the work flow, which contains your script to run. It doesn’t take long to set up.

The first step is to open Automator. This is located in your Applications folder. When it opens select Automator from the pop up list.

service automator

This will automatically put your Service into the required folder and update your system.

The next step is to add your code to the Work flow. To do this first select no input from the first drop down this allows the script to run from any application and allows you to use the short cut any time. The new service menu in Mac OS X 10.6 only shows certain options when certain applications are selected, this change makes sure you can run your app any time you want.

To run your shell script which you have created select the “Run Shell Script” workflow from the list, it is under utilities. In the text box copy and paste the code you have created. You can leave the drop down options intact.

automator shell script

The advantage with Automator is that you can run normal actions after the script. This is useful if you want to do something relatively simple but don’t know how to code it with a Shell script.

When you have finished save your script. Give it a name, this name is visible from the Service menu so make sure you give it something useful, simple and short. All finished work flows are stored in /Users/[name]/Library/Services if you need to modify or delete them.

The final step is to give the work flow a short cut so you can run it any time. To do this open up System Preferences > Keyboard > Keyboard Shortcuts > Services. You new Shell script will be at the bottom of the list. Double click on the right hand side of the Service option and add your short cut by pressing the required keys. Note you need to make sure you don’t use a short cut that is used by another program as you may run into conflicts. Add two or more modifier keys such as Shift, Option, Command and Function to make sure you don’t run into problems.

system preferences keyboard short cut

Any short cut will take a minute or two to update everything and you will be able to use your script with a short cut.

service short cut

Hopefully everything works. If you have any problems have a mess around and see if you can make it work. If you still have problems search the web or ask a question below. I hope that this round up post enables you to run any shell script with a short cut.


If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips