1

Whenever I am not in a browser or in my text editor, most of my time on my mac is spent on the terminal.

What's a quick, generic way to figure out how to run a gui program from the bash shell? It seems like we always need to run around and find out that program xyz can be called as 'abc'.

For example, Sublime Text's is 'subl', Kaleidoscope is 'ksdiff'. Great, but you need to look these up for each and every program. And there are lots of identical questions, about Finder for example.

What is the best Mac approach to figuring out the command line "alias" for an any app? Can I make use of the Activity Monitor if the program is open? Do I have to go nose around in the Applications folder? If so, how can I tell the "command line alias file" from the others?

Or can I use "ps aux" in bash? For example, on Linux or on Windows, "foo.exe" in the list of processes means that you could just type "foo.exe" to launch that program. But Sublime shows up as Sublime Text, not 'subl', so don't think that would work.

3

Bot Sublime Text and Kaleidoscope are special cases as they install either a helper utility or themselves somewhere in your $PATH.

The easiest way to open any application from /Applications is to run

open -a APPNAME

in Terminal, e.g.

open -a Pages       # opens Pages
open -a "App Store" # opens the App Store
  • Yes, that does seem to work, and I can also open a file/url in Firefox with it. I knew about open, but didn't realize you could use -a to launch apps with it or specify another program than the default to open the file. Thanks. – JL Peyret Apr 22 '15 at 17:28
0

Just to elaborate on the answer by patrix. Specifically on how to figure out what to put in the -a flag.

If I use ps aux on the command line, it will tell me which appname to use.

audrey:tests jluc$ ps aux | grep Sub
jluc            30721   0.0  5.0  3746992 418976   ??  S    Tue04pm  42:37.43 /Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2 -psn_0_983280
jluc            55934   0.0  0.0  2423368    188 s004  R+    8:07pm   0:00.00 grep Sub

See that Sublime Text 2? That's what you want.

creating a file and opening it (made sure it was an unknown extension rather than having it pick up Sublime by association.

audrey:tests jluc$ echo bzp > test.bzp
audrey:tests jluc$ open -a "Sublime Text 2" test.bzp

That works.

Finally, if you find you are often using that app from the command line, you can alias it.

alias open_sublime='open -a "Sublime Text 2"'

This is one for Affinity Designer

ps aux | grep Aff

results

jluc            56148   1.2  1.7  4206616 139500   ??  S     8:29pm   0:04.79 /Applications/Affinity Designer.app/Contents/MacOS/Affinity Designer
jluc            56158   0.0  0.0  2432784    632 s004  S+    8:30pm   0:00.00 grep Aff

and now the alias

alias open_aff_design='open -a "Affinity Designer"'
0

If you find you keep needing a program in the Terminal:

Both

open -a "AppName"

or

open /pathtoapplication would work...

and setting up an alias in your .bashrc file would be good. e.g. alias open_app='open /pathtoapp'

To edit the .bashrc:

1) In your Home directory open .bashrc in your favorite editor (e.g. vi .bashrc)

2) Insert as many aliases as you would need

3) Save the file

4) Type source .bashrc or . .bashrc to do two things...to do a syntax check and immediately apply your changes

Step 4 is important -- if you make an error it could come back to haunt you if you restart without checking...nothing earth shattering, but more annoying... Plus, you get the changes immediately applies and can test them out.

You must log in to answer this question.

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