tags:

views:

826

answers:

5

I want to launch an app on OSX from a script. I need pass it command line arguments. Unfortunately, 'open' doesn't accept command line args.

The only option I can think of is to use 'nohup myApp > /dev/null &' to launch my app so it can exist independently of the script that launches it.

Any better suggestions?

+3  A: 

An application bundle (a .app file) is actually a bunch of directories. Instead of using 'open' and the .app name, you can actually move in to it and start the actual binary. For instance:

$ cd /Applications/LittleSnapper.app/
$ ls
Contents
$ cd Contents/MacOS/
$ ./LittleSnapper

That is the actual binary that might accept arguments (or not, in LittleSnapper's case).

MathieuK
The binary accepts arguments, I am sure. I wrote it. Invoking 'open' doesn't allow passing arguments. I am pretty sure about this.And yes, my script is calling 'open binary' directly, not trying to open the bundle.
psychotik
@psychotik: He's not saying to call "open binary." He's saying to directly execute the binary.
Chuck
That won't work for me. Directly executing the binary results in it being a child process of my script, which I definitely do not want. Hence, the need to use open/nohup
psychotik
If it is a shell script, use 'exec' to replace the script process with the actual executable.
Jonathan Leffler
This is a python script invoking a shell command using os.system(). In any case, 'exec' launches my app as a child process so it's the same issue.
psychotik
+4  A: 

OS X app bundles aren't designed to be passed command line arguments; the conventional mechanism is to use Apple Events for files like here for Cocoa apps or here for Carbon apps. You probably could do something kludgey by passing parameters in using environment variables.

Ned Deily
My kludgey approach is to invoke the executable directly with command line args using nohup - if the environment-vars-kludge less kludgey?
psychotik
Probably not. If it works for you, go with it. The larger point is that open(1) is the cli equivalent of what happens when a user does a double-click or an "Open" in the Finder and none of those mechanisms support conventional command line arguments.
Ned Deily
+1: You shouldn't be using command-line arguments for Mac OS X GUI applications.
S.Lott
A: 

I would recommend the technique that MathieuK offers. In my case, I needed to try it with Chromium:

> Chromium.app/Contents/MacOS/Chromium --enable-remote-fonts

I realize this doesn't solve the OP's problem, but hopefully it saves someone else's time. :)

Paul Irish
+4  A: 

As was mentioned here, the 'open' command in 10.6 now has an 'args' flag, so you can call:

open -n ./AppName.app --args -AppCommandLineArg

John McDonnell
A: 

With applescript:

tell application "Firefox" to activate

Keith