In OS X, how to open an application with command line arguments?
August 10, 2008 10:01 AM   Subscribe

OS X terminal help. How do I open an application with command line arguments?

Application FOO supports a number of command line arguments. From OS X's terminal,

$ open FOO.app (this works fine)

$ open FOO.app -r
open [470] No such file: /Users/Izner Myletze/ -r

$ open 'FOO.app -k'
open[471] No such file: /Users/Izner Myletze/FOO.app -k

How do I start FOO with -r or -k?
posted by Izner Myletze to Computers & Internet (6 answers total) 4 users marked this as a favorite
 
from this faq:
Sometimes, you want to launch a separate process of Carbon Emacs or Aquamacs, and want to pass it command line arguments. You can do like this: nohup /Applications/Emacs.app/Contents/MacOS/Emacs -q &.
that seems to imply that you have to search inside the ".app" directory (bundle) to find the executable, and invoke it yourself (nohup is irrelevant here - it's just to stop the application exiting when you close the console window).
posted by not sure this is a good idea at 10:20 AM on August 10, 2008


open doesn't support command line arguments, based on a cursory reading of it's man page. Why don't you just call the application directly?

$ /Applications/FOO.app/Contents/MacOS/FOO -xyz
posted by nomisxid at 10:48 AM on August 10, 2008


If you have problems figuring out where the actual executable is in a .app you can right click it and choose "Show Package Contents"
posted by OwlBoy at 11:18 AM on August 10, 2008


open does support cmd line args, based on its man page (see the example on opening Xcode) . The trick to starting FOO.app is to either provide the full path name like /Applications/Utilities/FOO.app, or cd to the folder where FOO.app lives, then call it there.

Or, if you are ambitious, append your various application directory paths to the PATH environment variable. Then you can start up any app from open, without the hassle.
posted by chookibing at 1:37 PM on August 10, 2008


chookibing, open does not support passing command-line arguments to the app that gets launched. Half the point of open is to be able to open a file (or url or something) without necessarily having to launch a new instance of the app. (The app gets the filenames, etc., via an AppleEvent.)

nstiagi and nomisxid's suggestions are what I do in this case.
posted by hattifattener at 1:54 PM on August 10, 2008


If you do this a lot, put (a symbolic link to) the executable in your path. Add the line
export PATH=$HOME/bin:$PATH
at the bottom of the file /Users/you/.bash_profile. Then from a new shell type
$ mkdir $HOME/bin
$ cd $HOME/bin
$ ln -s "/Applications/Foo.app/complicated/FOO" .
Now, from any shell, you can say
$ FOO -r -k
like on a normal unix machine.
posted by fantabulous timewaster at 8:33 PM on August 10, 2008


« Older Coolest burning bulbs?   |   A sexual Catch-22. Newer »
This thread is closed to new comments.