Skip to main content

Create custom keyboard shortcuts in Mac using Automator



Having been a windows user for the most part of my life - switching to a mac had its own sets of challenges, especially when it was going to be my go-to machine in terms of work and leisure. While I'm still getting used to the Mac environment, one thing that I miss, is the ability to create simple text files anywhere by right-clicking and selecting a menu option or a keyboard shortcut. Mac Automator to the rescue.

Mac Automator lets you automate repetitive tasks by simply dragging built-in actions and creating a workflow to achieve a task. It also lets you define your own custom actions using AppleScripts.

Firstly open the Automator app in your mac and select File > New. Next, select the type of your document as Quick Action. Change the Workflow receives to - no input in Finder. Leave the rest of the options as it is. The top section should look like this  


Next, add a javascript, in order to find the current location in the Finder. In the left panel, make sure to select the top-level Library element and search for Run Javascript. Then drag the action to the workflow window and add the below javascript code.

Next we will set the value returned from this javascript function and set it to a variable. Search for Set Value of Variable and drag it to the workflow. Click on the dropdown and create a new variable by it a name current path. The variables section should look like this


Next, search for the New Text File action and drag it to the workflow window. File format can be selected as plain/rich text. The initial file name can be configured using the save as field. Change the where field to the variable value by dragging it from the variables window. The New Text File section should look like this 


Let's save the Quick action by going to File > Save and giving it a meaningful name such as CreateNewFile. Once you do that you should find this quick action under Finder > Services > CreateNewFile. Clicking on the menu item should create a new text file in your current location as expected. Let's go one step further and open up the file as soon as it's created.

Search for the Open Finder Items action and drag that to the end of the workflow
 

Now when we run the quick action it should create and open the text file in the current finder location. The text file should contain the current location text by default, if in case you need a blank text file, then you can add another javascript action in between the Set Value to Variable and New Text File in order to clear the text being passed.

The Workflow should look like this once all the actions are added.


Next, assign a keyboard shortcut to this Quick Action by going to the System Preferences > Keyboard > shortcuts > services and change the shortcut key for our newly created CreateNewFile action. Then we can just use this keyboard shortcut anywhere in the finder to create and open a new text file.

As you can see Mac Automator can make our life much easier by letting us build pretty sophisticated workflows in order to automate our daily tasks.