Create Context Menu Items in Mac Finder

By  on  

As much as I like exercising my command line skills, for many tasks I'd rather click a time or two.  The problem is that yarn install, brew install, and other package managers don't come with UI extending knowledgable people like us need to find a way to shoehorn those functionality into a UI.  That UI on Mac is Automator; let's explore how we can add custom context menu items within macOS Finder!

Creating a Context Menu Item with Automator

The example we'll use is creating a context menu to unrar rar archives.  The following steps will have you on your way to adding a context menu within macOS Finder:

  1. Open Applications -> Automator
  2. File -> New in the menu bar
  3. Chose a document type of Service

  4. Within the right pane's top panel, choose files or folders from the first dropdown and then from the second dropdown.
  5. Within the left actions pane, select Run Shell Script

  6. When the Run Shell Script box appears in the right pane, change the Pass input value to to arguments.
  7. Now you can write whatever shell scripting you'd like, receiving the file arguments as $@.  My script to unrar'ing files is overly simple:
    # Enter the first file's directory
    current_path=$(dirname "$1")
    cd "$current_path"
    # For every file, unrar it to the current directory
    for f in "$@"
    	/usr/local/bin/unrar x "$f"
    # Exit 0 so annoying errors don't popup 
    exit 0

    You can add additional checks to ensure the file is of the correct extension and other validation using a bit more scripting.
  8. File -> Save in the menu bar to save the Automator task.  The name you save the task as is what will display as the context menu name.

Debugging and Testing the Context Menu Item

The best method for testing and debugging an Automator task is by adding additional actions to the task to simulate real usage.  In our case, adding a Get Specified Finder Items action allows us to choose a valid file and test the outcome of the action:

Automator provides error and success messages in when running tasks, a luxury that using the context menu may not provide you.  When you're satisfied that your Automator task is working properly, delete any temporary debugging actions you created.

Using the Context Menu Item

Right-click any files or folders in Finder (in our case, just .rar files) and choose Services -> (Your Task Name Here):

Your task will execute in the background.

While I pride myself on improving my command line skills, I wish I had researched Automator task creation years ago.  Downloading a file to finder and then jumping over to command line is sometimes inconvenient -- sometimes it's just nice to perform a few clicks instead of remembering commands and argument formats.

Recent Features

  • By
    Interview with a Pornhub Web Developer

    Regardless of your stance on pornography, it would be impossible to deny the massive impact the adult website industry has had on pushing the web forward. From pushing the browser's video limits to pushing ads through WebSocket so ad blockers don't detect them, you have...

  • By
    Page Visibility API

    One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else? When do they come back?

Incredible Demos

  • By
    CSS Vertical Center with Flexbox

    I'm 31 years old and feel like I've been in the web development game for centuries.  We knew forever that layouts in CSS were a nightmare and we all considered flexbox our savior.  Whether it turns out that way remains to be seen but flexbox does easily...

  • By
    Create a Download Package Using MooTools Moousture

    Zohaib Sibt-e-Hassan recently released a great mouse gestures library for MooTools called Moousture. Moousture allows you to trigger functionality by moving your mouse in specified custom patterns. Too illustrate Moousture's value, I've created an image download builder using Mooustures and PHP. The XHTML We provide...


  1. Akis

    Thank you for all your tips / tricks :) I really appreciate them. But this one is not complete I think because /unrar is not an app or executable file. Where I can find and install it?

    • unrar needs to be installed with a package manager like homebrew.

    • Akis

      Thank you for your response. I did a little google search and I found the solution a couple of minutes after posting my initial question :) Forgive me. Now I am trying to add the specific variable into the script, so every RAR file to unrar it’s content within a same-name-as-the-file folder.

  2. I don’t know how to work with mac apps and make it compatible to iOS devices.

  3. sam

    The above method creates a sub menu item and you have to be in the parent directory for the menu item to work on a given directory.

    Following tool solves both of these issues. It allows you to open terminal from any directory while you are in the directory. The tool also allows you to write simple shell scripts to add more custom options to the right click menu. The tool is free and there is a GitHub link on the tool’s page if you want to check the source.

    You can get the tool here:

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!