Calling a Chrome application

When I have a Chrome application open, then run an applescript that calls Chrome browser (for example, opening a URL in incognito mode), it overrides the Chrome application instance (for example, it opens the URL in the frontmost window of that Chrome application). This doesn’t happen if Chrome and the Chrome application are both open at the same time.

I thought it might be how it is (not) registered, as the Info.plist has only two keys.

<key>CFBundleExecutable</key>
<string>application</string>
<key>CFBundleIconFile</key>
<string>icon</string>

How can I always call the right application from applescript?

PS I actually use Chromium, but referred to Chrome above, as it might be easier to find for others that have the same problem.

Here you can try making a Chrome application.
And here’s a list of Chromium command line switches.
Yet I couldn’t find a way to properly refer to it from applescript.

I’ve now added the following keys to Info.plist:

<key>CFBundleDisplayName</key>
<string>Chromium MyApplication</string>
<key>CFBundleExecutable</key>
<string>Chromium MyApplication</string>
<key>CFBundleIconFile</key>
<string>Chromium MyApplication</string>
<key>CFBundleIdentifier</key>
<string>org.chromium.Chromium-MyApplication</string>
<key>CFBundleName</key>
<string>Chromium MyApplication</string>

If I have none or one instance of Chromium running, MyApplication launches with either of these:

launch application id "org.chromium.Chromium-MyApplication"
tell application "Finder" to launch application id "org.chromium.Chromium-MyApplication"

-- event log
tell application "Chromium"
	launch
end tell

But if I try to activate it and Chromium was already running, latter will gain focus.

tell application id "org.chromium.Chromium-MyApplication" to activate

-- event log
tell application "Chromium"
	activate
end tell

At least the running property seems to always return the right value, regardless of another Chromium instance.

tell application id "org.chromium.Chromium-MyApplication" to return running

But this will also return true if MyApplication is running.

tell application id "org.chromium.Chromium" to return running

Any ideas?

In order for an applescript to correctly target Chromium browser instead of a Chromium application, former needs to be running. But that I couldn’t achieve in plain applescript with tell application "Chromium" to launch, nor by calling it by id “org.chromium.Chromium”, apparently because there’s an instance already running for the Chromium application. I used instead the open shell command, as it’s idempotent, i.e., it will launch Chromium browser only if it’s not running, regardless of instances of Chromium applications.

do shell script "open -a Chromium"

If I add the above keys to Info.plist, MyApplication will register and I can target it both as Chromium (in which case it will target the most recently launched Chromium application) or as MyApplication.

tell application "Chromium" to quit
tell application "MyApplication" to quit