Friday, November 8, 2013

The OSX ‘open’ command

A few days ago I was asked “how can one open more than a single instance of an application in OSX?”. The question was raised because by default OSX will open the already running application instance when an application icon is clicked (or entered via spotlight) more than once.
My first guess was to invoke the application executable directly from the command line - and it worked. But then it made me think maybe there’s a better way to do it, so I found the open command. This command is quite versatile, allowing one to “open” a file with its default handler application or with an alternative one, open any file with a text editor, stream the standard input to a text editor, fix applications which has windows that has gone out-of-view and more. For the above requirement, the “-n” flag can be used, such as:
open -n /Application/RStudio.app
The application becomes independent from the terminal session and the prompt can be used to re-launch another instance immediately. Simple and elegant.

No comments:

Post a Comment