Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch an app on OS X with command line

Tags:

macos

People also ask

How do I run a program from Terminal?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

How do I force an application to open on a Mac?

Control-click the app icon, then choose Open from the shortcut menu. Click Open. The app is saved as an exception to your security settings, and you can open it in the future by double-clicking it just as you can any registered app.


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

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


In OS X 10.6, the open command was enhanced to allow passing of arguments to the application:

open ./AppName.app --args -AppCommandLineArg

But for older versions of Mac OS X, and because 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 could also probably do something kludgey by passing parameters in using environment variables.


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).


In case your app needs to work on files (what you would normally expect to pass as: ./myApp *.jpg), you would do it like this:

open *.jpg -a myApp