How can I open the Atom editor from the command line in OS X?

MacosCommand Line-InterfaceAtom Editor

Macos Problem Overview


I have the Atom editor and was wondering how you can open a file or folder from the terminal in Atom. I am using a Mac. I am looking for a way to do this:

atom . (opens folder)

atom file.js (opens file)

atom (opens editor)

Is this possible and how do I set it up?

Macos Solutions


Solution 1 - Macos

With the Atom editor open, in the menu bar:

Click AtomInstall Shell Commands

atom-add-shell-commands

You should expect to see:

atom-commands-installed

Potentially restart your terminal (I did it just out of habit and am not sure if you need to).

Solution 2 - Macos

When Atom installs, it automatically creates a symbolic link in your /usr/local/bin folder. However, in case it hasn't, you can create it yourself on your Mac:

ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom

Now you can use atom folder_name to open a folder and atom file_name to open a file.

Solution 3 - Macos

Roll your own with user3283997's solution, or in Atom, choose the menu option AtomInstall Shell Commands. This creates two symbolic links in /usr/local/bin.

apm -> /Applications/Atom.app/Contents/Resources/app/apm/node_modules/.bin/apm
atom -> /Applications/Atom.app/Contents/Resources/app/atom.sh

The atom command lets you do exactly what you're asking. apm is the command line package manager.

Solution 4 - Macos

For Windows 7 x64 with default Atom installation add this to your PATH

%USERPROFILE%\AppData\Local\atom\app-1.4.0\resources\cli

and restart any running consoles

(if you don't find Atom there - right-click Atom icon and navigate to Target)

enter image description here

Solution 5 - Macos

The symlink solution for this stopped working for me in zsh today. I ended up creating an alias in my .zshrc file instead:

alias atom='sh /Applications/Atom.app/Contents/Resources/app/atom.sh'

Solution 6 - Macos

On macOS you can add it to your ~/.bash_profile

as

alias atom='open -a "Atom"'

and from terminal just call

atom filename.whatever

Solution 7 - Macos

Open the application by name:

open -a 'Atom' FILENAME

Solution 8 - Macos

For Windows 10 and the new release of Atom, I solved the problem by adding in my environment variable on the "PATH" row:

%USERPROFILE%\AppData\Local\atom\bin

Solution 9 - Macos

In addition to sbedulin's answer (greeting, lovely Windows users!):

The general path on Windows should be

%USERPROFILE%\AppData\Local\atom\bin

If you are using a Bash emulator like Babun, you'd better checkout the shell files, which are only available in the real application folders.

/c/User/<username>/AppData/Local/atom/app-<version>/resources/cli/apm.sh # Or atom.sh

Solution 10 - Macos

I’ve noticed this recently with all new Macs here at my office. Atom will be installed via an image for the developers, but we found Atom is never in the Application folder.

When doing an ls on the /usr/local/bin folder, the path for atom will show something like "/private/var/folders/cs". To resolve this, we just located file atom.app and copied it into the application folder, and then ran the system link commands provided by nwinkler which resoled the issue. Developers can now open Atom from the command line with "atom" or open the current projects from their working directory with "atom ."

Solution 11 - Macos

Make sure to put (move) "Atom" into the Application directory.

Enter image description here

Solution 12 - Macos

Install Shell command

Go to your terminal and locate your directory. Run this command:

atom index.html 

index.html is just an example.

Solution 13 - Macos

On Linux && Mac OS-es type "atom ." in terminal.

Solution 14 - Macos

Another simple solution is to add /usr/local/bin to your PATH environment variable. I had the same issue, and I installed shell commands (see shaheenery's response). The symbolic links already existed and were pointing to the correct destination (see thomax's response), however I would still get 'not found'. I'm using Korn Shell btw.

Here's what I did:

  1. Open your ~/.profile file using your choice of editor (in my case, emacs ~/.kshrc)
  2. Add this line: export PATH="/usr/local/bin:${PATH}"
  3. Save and exit
  4. Restart terminal or source ~/.profile
  5. Test with atom -h

Solution 15 - Macos

Upgrading Atom appears to break command line functionality on the occasion. It looks like in my case it created two versions of the application instead of overwriting them. It occurs because the new file structure doesn't match file paths created by AtomInstall Shell Commands. In order fix the issue, you'll need to do the following.

  1. Move "Atom X" from Documents into Applications (why it ended up in here, I have no idea)
  2. Rename "Atom X" to "Atom"
  3. Might need to restart your terminal and Atom

After that, everything should work just like it did before.

Solution 16 - Macos

With ConEmu on Windows 10 I couldn't call atom from the console even after I added %USERPROFILE%\AppData\Local\atom\bin to PATH in environment variables. I just added

alias atom="C:/Users/me/AppData/local/atom/app-1.12.7/atom"

to my .bashrc file.

Solution 17 - Macos

I had the same issue which I resolved by first moving Atom.app from downloads to Applications. Then under Atom's menu options, I selected "Install Shell Commands".

Solution 18 - Macos

I had problems due to Atom being unable to write its logfile when starting from the command line. This cured it.

sudo chmod 777 ~/.atom/nohup.out

Solution 19 - Macos

Add the path (:/usr/local/bin/) in the shell profile file.

Mac: file $home/.bash_profile

export PATH=$GOPATH/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:$PATH

Solution 20 - Macos

I am on MinGW Bash, so I have created the ~.profile file with the following:

alias atom='~/AppData/Local/atom/bin/atom'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndersView Question on Stackoverflow
Solution 1 - MacosshaheeneryView Answer on Stackoverflow
Solution 2 - Macosuser3283997View Answer on Stackoverflow
Solution 3 - MacosthomaxView Answer on Stackoverflow
Solution 4 - MacossbedulinView Answer on Stackoverflow
Solution 5 - MacosscottmcallisterView Answer on Stackoverflow
Solution 6 - MacostruskView Answer on Stackoverflow
Solution 7 - MacosDejay ClaytonView Answer on Stackoverflow
Solution 8 - MacosLaurentView Answer on Stackoverflow
Solution 9 - MacosParis Qian SenView Answer on Stackoverflow
Solution 10 - MacosGovnaView Answer on Stackoverflow
Solution 11 - MacosIzhari Ishak AksaView Answer on Stackoverflow
Solution 12 - MacosRayView Answer on Stackoverflow
Solution 13 - MacosGoran_Ilic_IlkeView Answer on Stackoverflow
Solution 14 - MacosJason RobinsonView Answer on Stackoverflow
Solution 15 - MacosAsh BlueView Answer on Stackoverflow
Solution 16 - MacosDaniel LizikView Answer on Stackoverflow
Solution 17 - Macoshal9000View Answer on Stackoverflow
Solution 18 - Macosandrew pateView Answer on Stackoverflow
Solution 19 - MacosPeter ZhangView Answer on Stackoverflow
Solution 20 - MacosMartin KuncView Answer on Stackoverflow