How to launch a GUI app in Applications folder from command line

applicationsterminal

I would like to launch a GUI app that is in the Applications folder from the command line as opposed to clicking the icon in the Finder or in the Dock. The reason I want that is to be able to launch it as root using sudo as opposed to launching it as my default user.

When I went into the Applications, this is what it looked like:

/Applications/IntelliJ IDEA 13 CE.app@16:16:42>ls -la
total 40
drwxr-xr-x@ 10 myuser  admin    340 Dec 17 14:07 .
drwxrwxr-x+ 68 root           admin   2312 Jan 20 18:00 ..
drwxr-xr-x@  6 myuser  admin    204 Dec 17 14:08 Contents
-rw-r--r--@  1 myuser  admin  11358 Dec 17 14:06 LICENSE.txt
-rw-r--r--@  1 myuser  admin    127 Dec 17 14:06 NOTICE.txt
drwxr-xr-x@ 14 myuser  admin    476 Dec 17 14:09 bin
-rw-r--r--@  1 myuser  admin     10 Dec 17 14:01 build.txt
drwxr-xr-x@ 85 myuser  admin   2890 Dec 17 14:06 lib
drwxr-xr-x@ 29 myuser  admin    986 Dec 17 14:06 license
drwxr-xr-x@ 30 myuser  admin   1020 Dec 17 14:06 plugins

Funny thing is, in the Finder, IntelliJ IDEA 13 CE shows as a clickable icon which launches the app. But at the terminal level, it is actually a directory with contents I do not know how to navigate and manipulate to emulate a GUI click.

Best Answer

Simply use open:

open "/Applications/IntelliJ IDEA 13 CE.app"
open -a "IntelliJ IDEA 13 CE"

However, prepending sudo isn't enough to run as root. You'll need to run the actual binary:

sudo /Applications/ApplicationName.app/Contents/MacOS/ApplicationName