I want to run Applications in macOS as simple as it is on Linux: just type the app's name in the terminal. What is the best way to do this?
Example: I just installed Atom Nightly and would like to run it from the terminal with a command like 'atom' or 'atom-nightly'.
Would aliases be good for this, i.e alias atom="/Applications/Atom\ Nightly.app"? It's weird that I get some permission denied error..
What is the quickest way? (I'd really appreciate not having to do this for every app I install).
02 Answers
I recommend you use:
alias atom="open -a Atom\ Nightly"The open -a $APPNAME command is smart about finding GUI apps based on their user-visible name.
macOS GUI apps are packaged as ".app bundles" or "packages", which are actually special directory hierarchies. A traditional Unix shell like bash or zsh expect the file you invoke to be executable; either a shell script or an executable machine code binary file; you can't execute a directory. So if you want to invoke a GUI app from the command line, you must invoke its actual executable buried inside the .app bundle, which would usually be something like this:
/Applications/Atom\ NightlyThe reason you were getting that permission denied error was you were asking your shell to execute a directory, which is not executable (the "x" permissions bit on directories means it's traversable, but that's beyond the scope of this question).
Note that launching GUI apps from a shell only works when the shell lives inside a GUI session, such as a shell running within a terminal emulator app. It doesn't work from a shell that's not associated with any GUI session, such as when you've SSH'd into the Mac from some other machine.
1Why not use Spotlight?
Cmd/Space, start to type, hit Return when the correct name is selected [which you can do with arrows if you don't want to click.] If you don't have many things with 'atom' in the name, you're probably down to 4 or 5 keystrokes to open it from anywhere in the OS.
I don't have Atom Nightly, but here's an example for FaceTime, which everyone has. 5 keystrokes from start to finish, Cmd/Space, F, A, C, Return.
No pre-programming or aliases required. Using the system for what it's made for, rather than constructing elaborate hacks which take longer & need doing for every app.
2