Friday, October 19, 2018

#1 2018-03-10 12:35:06 pm

msh
Member
Registered: 2014-01-25
Posts: 113

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.


Filed under: chrome, chromium

Offline

 

#2 2018-03-13 10:01:40 am

msh
Member
Registered: 2014-01-25
Posts: 113

Re: Calling a Chrome application

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.

Offline

 

#3 2018-03-18 09:14:17 am

msh
Member
Registered: 2014-01-25
Posts: 113

Re: Calling a Chrome application

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:

Applescript:

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.

Applescript:

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.

Applescript:

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

But this will also return true if MyApplication is running.

Applescript:

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

Any ideas?

Offline

 

#4 2018-03-23 05:56:23 pm

msh
Member
Registered: 2014-01-25
Posts: 113

Re: Calling a Chrome application

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.

Applescript:

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.

Applescript:

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)