Jump to content

OSX Bash Script Execution through Keyboard Shortcut


Leon

Recommended Posts

  • Administrators

Original post: http://web.onassar.com/blog/2012/06/30/osx-bash-script-execution-through-keyboard-shortcut/



While the full example is pretty thorough, I wanted to walk through the process I undertook to have some bash code/script run through a shortcut key. I'm going to split this into two pieces.

Creating a Service

From any application, you can go to the Application Menu, down to Services and choose one. These services can do a variety of things, such as copy/paste the open file's text, upload the file through an FTP application, etc.

We want to create a service that runs a bash command/script.

  1. Prepare the bash command and test it in Terminal.app
  2. Open up Automator.app
  3. Create a new Service
  4. In the left column, under the Library header, choose the Utilities option
  5. In the column to the right, double-click the Run Shell Script option
  6. Paste your command into the textarea
  7. Above, under the Service received selected drop-down list, choose no input
  8. Hit Command-S to save it, and give it a name (in my case "rsync")
Creating the shortcut key

Now that the service has been created, we want to make sure it is both accessible through the theServices submenu, as well as having a shortcut key bound to it.

Here are the steps to do both:

  1. Open up System Preferences.app
  2. Go to the Keyboard settings
  3. On the left, choose the Services option
  4. Scroll to the bottom, and ensure the rsync (or whatever name you gave it) option is checked
  5. When selecting the service, a button titled add shortcut should become visible. Choose this, and add your shortcut
  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...