Users sometimes need to run particular scripts repetitively on Mac OS. Finding that script and running it after pointing your terminal to the correct path becomes a tedious job. It’s a wise choice to assign a particular keyboard shortcut for the desired script or shell command. It means saving a few seconds as you can run that script without much hassle and time-wastage.
Automator: Choose shortcuts for scripts, commands etc.
We shall use a built in app called Automator to accomplish our goal. There are other third party apps available to run a script using keyboard shortcut, but we’ll use an Apple original app.
1. Give automator required accessibility permissions
You need to give permission to automator within accessibility before adding any shortcuts.
- Open Security and Privacy in System Preferences
- Scroll down and click Accessibility, unlock padlock icon at the bottom left, enter password and hit enter
- Under panel, allowed apps to control your computer, tick Automator
Now, you can use automator for keyboard shortcut.
2. Adding a script in Automator to assign keyboard shortcut
The script we are dealing here is a simple bash script. It opens Google website on Chrome browser upon execution. Similarly, you can also use other script using the same method.
- Open Script Editor in applications.
- Write do shell script “$HOME/Documents/Dump/google.sh”.
- Save it as an application.
Now, to assign keyboard shortcut to your application using automator, follow this procedure:
- Open Automator in applications.
- Choose Quick Action.
- In Workflow receives choose No Input, search for Launch Application and drag drop it in empty space.
- Choose options, select others and locate your script AppleScript app (In case you can’t select your application, make sure you rename it and don’t use spaces, Automator doesn’t identify an app name with spaces).
- Save quick action and give it a proper name.
Last, you need to assign a shortcut for the quick action you just added.
- Open System Preferences > Keyboard > Shortcuts.
- Scroll down and find Services, in the end you’ll find your recently added quick action.
- Select it and click Add Shortcut. Make sure you add a shortcut key which isn’t associated with any other program.
Now, whenever you’ll press the specific key combination, your intended script will run. In my case, whenever I press the shortcut keys, Google Chrome opens and it goes to Google.com.
Conclusion:
You can run any script or console command on Mac OS using a keyboard shortcut. It’ll save your time. All you need is to convert your script into an application using Apple Script and then attaching that application to a keyboard shortcut using Automator. The process is simple and you can extend it to any kind of command-line script or software.