Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active April 27, 2022 00:37
Show Gist options
  • Save idleberg/874790e8e3c8b1419e4439d0a48d2aa5 to your computer and use it in GitHub Desktop.
Save idleberg/874790e8e3c8b1419e4439d0a48d2aa5 to your computer and use it in GitHub Desktop.
“Open in Atom” in macOS context-menu

Open in Atom

  • Open Automator
  • Create a new Service
  • Set “Service receives selected” to files or folders in any application
  • Add a Run Shell Script action
  • Set the script action to /usr/local/bin/atom -n "$@"
  • Set “Pass input” to as arguments
  • Save as Open in Atom

Add to Atom

Let's repeat the steps above for a second entry, this time to add files or folders to an existing Atom window

  • Open Automator
  • Create a new Service
  • Add a Run Shell Script action
  • Set “Service receives selected” to files or folders in any application
  • Set the script action to /usr/local/bin/atom -a "$@"
  • Set “Pass input” to as arguments
  • Save as Add to Atom

Keyboard Shortcuts

You can assign a global shortcut to run the services we just created

  • Open “System Preferences”
  • Select “Keyboard” then the “Shortcuts” tab
  • In the left pane, click on “Services”
  • In the right pane, scroll to “Files and Folders”
  • Select “Open in Atom” (or “Add to Atom”) and click “add shortcut”
  • Select a shortcut

Edit Context Menu items

You might want to rename or edit the items we just created

  • Activate Finder
  • Click on “Finder” in the Apple menu, select “Services” then “Services Preferences”
  • In the right pane, scroll to “Files and Folders” and scroll to the item you want to edit
  • Right click the item and select “Open in Automator”
  • Edit and save

Alternatively, you can edit the workflow (e.g. ~/Library/Services/Open in Atom.workflow) in your preferred text editor

@chadhamre
Copy link

chadhamre commented Sep 19, 2017

Thanks for this! Very helpful. Do you know if it's possible to move it from under the right-click > services menu to be directly on the right-click menu?

@idleberg
Copy link
Author

I think it has been a deliberate decision by Apple not to provide ways to clutter the context menu in the ways Windows programs often do. However, whether entries to the context menu are nested within a sub-menu depends on the number of services. I currently have four items available in the top-level of the context menu. IIRC, they only get nested once you have 5 or more, so you could try and remove some unneeded services.

@oxguy3
Copy link

oxguy3 commented Nov 16, 2017

Cool guide, thanks! One issue though: this doesn't work quite right if your filename has spaces. This is fixed by putting quotes around $@ in the script action (i.e. /usr/local/bin/atom -n "$@").

And, just a personal preference: I find that having to manually decide whether I want to "Open" or "Add" is tedious (especially since it means I have two keyboard shortcuts instead of one). If you change the script action to /usr/local/bin/atom "$@" (no -a or -n flag), then Atom will intelligently decide whether to open a tab or window based on whether or not you already have a window open in this folder.

@j-greig
Copy link

j-greig commented Nov 27, 2017

When I select a folder in 10.12.6 this script (the version directly above this comment) opens a blank window, not the folder I have selected?

@ttristan
Copy link

awesome!

Copy link

ghost commented Dec 26, 2017

awesome! Thank you a lot

@si458
Copy link

si458 commented Jan 16, 2018

can you edit the gist so you have a set during the setup to tell the end user to 'Install shell commands'
I spent hours trying to work out why it kept popping up with '/usr/local/bin/atom: No such file or directory'
and it turns out you NEED to 'install shell commands' BEFORE

  1. Open Atom
  2. Click Atom
  3. Install Shell Commands
  4. Enter user password
  5. Done

@j77h
Copy link

j77h commented Mar 12, 2018

@idleberg
Do you know how to script the whole process?
For example, if preparing a PyQt5 app to install on Mac, I'd like to include a script that will add 'open with my app' to the finder context menu for certain file types. Doesn't matter if the user has to manually run the script, as long as it's simple for them.
For Windows I do it by adding items to the registry, which is scriptable in several ways (including a python winreg module).
For macOS, searching for an hour has found only GUI methods similar to yours, except at developer.apple.com.
Maybe the info I need is in one of the follwing areas,
but after looking through them for several minutes I didn't see anything obvious:
https://developer.apple.com/documentation/automator
https://developer.apple.com/documentation/installerjs

@JARVIS-AI
Copy link

I just want to mention one thing that as I pay some time to figure it out to solve it for this trouble, important one for this shell script in Automator

If you have several Shells in /etc/shell like ksh - tcsh - fish - bash - zsh - and so on
Just be sure that you set it to your default shell I mean bash in most of times

If you don't do this and its works leave it alone

First rule of programmer : If its works don't touch it :)

But if you don't set to def and it gives you the workflow error for that cannot complete the task do this

Enjoy scripting services in UNIX based OS

@illuzionnl
Copy link

Trying to get this to work on my mac, but fails to get the atom action script to show up in the shell automation. I did install the shell commands through atom like si458 mentioned above. If I do it through atom I don't get a password question so I also installed it through command line sudo apm install atom-shell-commands. Any clues to why im missing the action?

Side note which atom work properly and atom opens atom like it should.

@pkamb
Copy link

pkamb commented Jun 23, 2020

Thought I would drop a note to say that my app Service Station can used to easily customize the right-click menu.

Atom is one of the default options for text files:

Screen Shot 2020-06-23 at 12 27 07 AM

Service Station is implemented via a modern Finder Sync Extension. I like this better than the Services menu as you don't have to dig through a submenu packed with multiple other Services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment