1

Is there a way to return a list of all the installed text editors via the command line?

I think (I can't test to confirm) this answer inadvertently gives the equivalent for ubuntu:

sudo update-alternatives --config editor

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

I gave that a try on mac, but command not found.

2

No, there's no such command or list available in the Terminal.

The command you've found for Ubuntu is part of the so called alternatives system that is found mostly in Debian-based Linux distributions. It's not available on all Linux systems, it's not available on BSD based systems and definitely not available on macOS.

Also the update-alternatives command does not necessarily list all text editors on the system (you see your own list is pretty small). It is only lists those that are registered with the alternatives system, which is not all of them. Commonly GUI-based editors are not listed here for example.

Instead of alternatives, macOS has the concept of file associations or "preferred applications". As far as I recall, this predates alternatives. Application bundles on macOS contain information about the file types that the application is willing to support. The user can choose which application is by default used to open a specific file type - this means that you can associate for example JPEG files with the photo editing software of your own choice. However, this is for GUI programs - not command line utilities as such.

An easy way to list and manipulate file associations via the command line is to use the third party utility SwiftDefaultApps. It can be installed from HomeBrew Casks using this command:

brew cask install swiftdefaultappsprefpane

After installation you'll have a command available named swda. You can run it like this to get a list of file associations:

swda getUTIs
  • Thanks very much (saves me needlessly looking). Do you know if there’s any work around or hacky way to approximately get the list? Reason I need it is for a convenience function in python that will give the user some options to write and quickly open a file in the text editor they choose – stevec Oct 16 '20 at 6:39
  • Are you looking for a text editor to run inside Terminal.app? - Or a graphical text editor? – jksoegaard Oct 16 '20 at 6:45
  • in the graphical text editor, but i want to be able to provide the user a list of options (or provide a helpful error message if they select an editor they don’t have installed) – stevec Oct 16 '20 at 7:11
  • @stevec even under Debian as you show you do not get any GUI editors on the list + you don't get terminal editors like emacs So I don't think it is possible. The normal Unix way is for the user to set their preferred editor in EDITOR environment variable and calling programs use that. – mmmmmm Oct 16 '20 at 7:24
  • @mmmmmm You actually do get emacs in the list on Debian. The alternatives have some advantages over for example EDITOR - mainly it handles lots of other stuff than just editors. It can automatically populate the EDITOR environment variable for you. Note that if your preferred editor is for example "emacs", then you should really be specifying that in the VISUAL environment variable instead of the EDITOR variable, if you want to be fully "unixy" :-) – jksoegaard Oct 16 '20 at 7:46

You must log in to answer this question.

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