Markus G.
Markus G.

Reputation: 331

MAC OS X difference between "open APP.app" and "APP.app/content/MacOs/APP" shell scripts

Somehow I get a problem, if I call an application twice or several times but only one instance should be running (which is desired).

First some (probably necessary) background information:

So, I did some homework and could figure out following:

I was wondering WHY? Do you have any clues? What is the difference between open and directly call of the application?

I suggest that the info.pklist in App.app-package is making the open-call different to the direct call of App.app.

BTW: Unfortunately I already tried to add try-catch-blocks to debug the problem, but open does not give an output to terminal, it just opens the call whereas the direct call does not throw an error and everything works fine. Anyway, I believe it's more a MAC OS X problem than an App.app-problem.

Hopefully there's somebody with same problems and a solution for me

Don't hesitate to ask for more details, if needed.

Upvotes: 2

Views: 1140

Answers (1)

Markus G.
Markus G.

Reputation: 331

Short Version:

  • open starts the application with the LaunchService (and possible added launch-parameters in info.plist)
  • whereas direct call of the application just starts the application iself without any other launch-options

*Long Version *

I read through the open manual (man open; Source: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/open.1.html) and could figure out, that "the default application as determined via LaunchServices is used to open the specified files" if you click on an item.

So I read through the LaunchService-documentation and could figure out following:

"Opening Items by File-System Reference [...] default way: If the designated item is an application: [...] If the application is already running, it is activated (brought to the front of the screen) and sent an 'rapp' (“reopen application”) Apple event."

(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCTasks/LSCTasks.html#//apple_ref/doc/uid/TP30000999-CH203-TP9)

This reflects exactly my watching that if I click on the icon the second time, the app is just focussed/activated.

Thus I need the possibility to tell the application to open a new instance (oapp-event) instead of activating the already opened application (rapp-event)

Further reading lead me to following informations:

"Launch Options When opening an application (whether by itself or to open one or more documents or URLs), you can specify various launch options to control the manner in which it is launched or activated. These can include: [...] Whether to launch a new instance of the application, even if another instance is already running"

(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html#//apple_ref/doc/uid/TP30000999-CH202-BABBJHID)

Thus I only need to add the "launch option" to define, that a new instance should be created instead of activating the existing one. But there's not written what the launch-option for it is and how they will be applied to the application (I suggest it belongs into info.plist-file).

So at least this is the answer to my original question, so I posted it here.

open - starts the application with the Launch-Service (and the defined option-parameters in info.plist) whereas direct call of the application just starts the application iself without any other launch-options

Upvotes: 1

Related Questions