How do I run apple script on a particular instance of Firefox? I have three instances of Firefox called -

Firefox
Firefox 2
Firefox 3

They all live in the Applications folder and the difference is that they have different Firefox profiles and cookies.
I'd like to run an apple script that works on a particular instance of Firefox.
tell application &quot;Firefox&quot;
    activate
    tell application &quot;System Events&quot;
        keystroke &quot;n&quot; using {command down}
    end tell
end tell

tell application &quot;Firefox&quot;
    activate
    tell application &quot;System Events&quot;
        keystroke &quot;l&quot; using {command down}
        keystroke &quot;a&quot; using {command down}
        key code 51
        keystroke &quot;https://google.com&quot;
        key code 36
    end tell
end tell

If I run this with Firefox open then it works exactly how I want it to.
But, if Firefox is closed, but Firefox 2 or Firefox 3 are open then it has weird behavior.
It will replace the word Firefox with Firefox 2 or Firefox 3 (whichever is open and last active) and then it will run the script using that instance of Firefox which is not what I want.
To test the example AppleScript code, I duplicated Firefox and renamed the copy as Firefox 2.
This was texted under macOS High Sierra, using different scenarios:

Both Firefox and Firefox 2 running, with Firefox started first.

Firefox being frontmost.
Firefox 2 being frontmost.


Both Firefox and Firefox 2 running, with Firefox 2 started first.

Firefox being frontmost.
Firefox 2 being frontmost.


Just Firefox 2 running.

In all tested scenarios the example AppleScript code preformed as wanted, Firefox being the one acted upon, not Firefox 2.
I believe the key here is using the fully qualified pathname, e.g. &quot;/Applications/Firefox.app&quot; verses just &quot;Firefox&quot;.
tell application &quot;/Applications/Firefox.app&quot; to activate
delay 1
tell application &quot;System Events&quot;
    keystroke &quot;n&quot; using {command down}
    delay 1
    keystroke &quot;l&quot; using {command down}
    keystroke &quot;a&quot; using {command down}
    key code 51
    keystroke &quot;https://google.com&quot;
    key code 36
end tell


Note: The use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.