Quick Links

Are there particular Terminal commands you find yourself running several time a day? Do you wish you could trigger them quickly, with just a keystroke?

As it turns out, you can! We've shown you all the Mac keyboard shortcuts you should be using, but this gives you an opportunity to invent your own keyboard shortcut to do just about anything you can imagine with the Terminal. There are two main ways to accomplish this, so let's get started.

The Easy Way: iCanHazShortcut

The easiest way to add custom keyboard shortcuts for specific commands is to download iCanHazShortcut, a free Mac application with a terrible name. Installing couldn't be simpler: just drag the icon to your Applications folder.

icanhazshortcut-install

Then fire up the application. You'll find it in the menu bar.

icanhazshortcut-running

Click "Shortcuts" to bring up a list of current shortcuts.

icanhazshortcuts-window

Looks like we don't have any shortcuts defined right now. To change this, click the green arrow at bottom-right. This will bring up a two fields: one for the keyboard shortcut, another for the command you'd like to trigger.

icanhazshortcut-shortcut

Click the first field, then hit whatever keyboard shortcut you'd like to use. Next, click the second field and enter whatever command you'd like to trigger. For our example, we're going to use

        date "+The time is %H:%M" | say
    

 which makes our Mac say the current time out loud.

Click the green checkmark at bottom-right, and your done! Your keyboard shortcut will now run your command at will.

icanhazshortcut-preferences

Note that you can configure a few more things, if you like. The icon menu bar icon can be disabled, allowing you to run this application in the background. You can also set the application to run when you start up your computer.

The (Slightly) Harder, But Built-In Way: Automator

If you'd rather not use a third party application to trigger Terminal commands, there's another method, which works because macOS lets you set custom keyboard shortcuts for everything. To get started we're going to launch Automator, which you'll find in your Applications folder. We're going to create a new Service for your Mac.

automator-create-service

In the Actions section, click the "Utilities" sub-section, then drag "Run Shell Script" over to your workflow.

automator-shell-script

Next, paste your command.

automator-run-script-time

Again I've used

        date "+The time is %H:%M" | say
    

, which will read the current time out loud, but you can use whatever command you like. Save your workflow with a name you'll recognize, and we're done with Automator.

Next, head to System Preferences > Keyboard > Shortcuts. In the left panel click "Services," and scroll down until you see the service you just created---it should be under the "General" section.

automator-say-time-keyboard-shortcut

After setting this, you can trigger your service using whatever shortcut you defined. And because this is all native to the operating system itself, there's no program you need to leave running in the background.