16

I would like to set Atom as my default editor for open.

In order to do this, I set in my .bashrc:

export EDITOR="atom -nw"

and reload the file with source .bashrc. Anyway, when I try to open a text file through open filename, it always opens it with TextEdit.

I also tried variations of the above, such as export EDITOR=atom, or exporting VISUAL.

I am sure that .bashrc gets loaded on login.

What am I missing/doing wrong?

1

5 Answers 5

17

The open command is part of OS X and uses Finder's default “Open With…” application to open the file, just like double-clicking it in Finder. $EDITOR is used for things like fc where it is used as the default command-line editor (a replacement for vim or emacs).

To use Atom with the open command, you can select a file of the type you want in Finder, press ⌘ command+I for “Get Info”, and then change “Open With:” to Atom, and click “Change All…”.

Alternatively you can define an alias like

alias e="atom -nw"

in your .bashrc and then run e file-to-edit.txt whenever you want to edit a file in Atom.

2
  • Thank you. I guess I will stick to opening atom through the command line explicitly.
    – link
    Commented Aug 2, 2014 at 13:24
  • This answer is useless, the question is common and simple, no one wants TextEdit to show up when they click ANY sort of text file, the default should always point to Atom (or whatever editor). Commented Mar 28, 2020 at 18:35
7

thee's answer doesn't work for Yosemite and El Capitan - use this one instead:

defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.github.atom;}'
2
  • 2
    Didn't work for me
    – abc123
    Commented Mar 1, 2016 at 14:30
  • Note, this requires a restart after the command (at least it did for me on High Sierra).
    – golmschenk
    Commented Apr 6, 2018 at 19:18
7

The actual answer is:

export EDITOR="/Applications/Atom.app/Contents/MacOS/Atom -nw"

3

Just right (or control) click a file of the type you want to change and:

"Get Info" -> "Open with:" -> (Select your program of choice) -> "Change All"

You'll have to do this once for each extension (.txt, .rtf, etc.) you wish to update.

1
  • This was the only one that helped. Thank you. Commented Jan 30, 2020 at 5:44
1

Following this answer on Stackoverflow, the following command should work:

defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.github.atom;}'

I am not sure how fare this works through. For me, open /etc/hosts opened the file in Atom as expected, but open demo.properties did not.

Edit: Might not work on Yosemite and above, see this answer for a modified version.

2
  • demo.properties possibly is not registered as a text file
    – mmmmmm
    Commented Dec 27, 2014 at 0:28
  • This does not work on macOS Mojave or higher. Commented Oct 31, 2019 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .