How to launch an app on OS X with command line - The best way

Viewed 221750

I want to launch an app on OSX from a script. I need to pass some 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?

14 Answers

You can launch apps using open:

open -a APP_YOU_WANT

This should open the application that you want.

Lots of complex answers when you can simply access Applications folder and type:

open -a [APP NAME]

This is it!

Simple, here replace the "APP" by name of the app you want to launch.

export APP_HOME=/Applications/APP.app/Contents/MacOS
export PATH=$PATH:$APP_HOME

Thanks me later.

Why not just set add path to to the bin of the app. For MacVim, I did the following.

export PATH=/Applications/MacVim.app/Contents/bin:$PATH

An alias, is another option I tried.

alias mvim='/Applications/MacVim.app/Contents/bin/mvim'
alias gvim=mvim 

With the export PATH I can call all of the commands in the app. Arguments passed well for my test with MacVim. Whereas the alias, I had to alias each command in the bin.

mvim README.txt
gvim Anotherfile.txt

Enjoy the power of alias and PATH. However, you do need to monitor changes when the OS is upgraded.

To Create a New Text File OR open an existing one, in any folder, using a Text/Code Editor like the Free TextMate app on MACOSX, use this command on Terminal:

open -n /Applications/TextMate.app --args "$PWD/some file.txt"

Instead of a Text File, you can use any file type, based on your app's requirements and its support for this syntax.

This command also simulates the New Text Document Here Command on Windows and has been tested on MacBook Pro 2021 and Monterey 12.2.1 successfully.

Related