Specifying a Window (Chrome or Safari) From Which to Run Multiple Scripts

I have a number of macros that execute different scripts against Google Chrome or Safari. I typically trigger them one at a time, and the result is a pop-up window in the browser with a table of 'stuff'. Once done, I close that window, then run my next script.

I want to create a macro that runs all the scripts, one after the other, which will give me multiple pop-up windows (I am a glutton for punishment it seems):

  • My browser window
    • Run script 1
    • Run script 2
    • Run script 3

The problem is that when Script 2 is run, it tries to run it agains the newly created pop-up window from Script 1. And so on …

  • My browser window
    • Run script 1
      • Run script 2
        • Run script 3

So what I need is a way of naming that initial window or whatever so that all the subsequent scripts run from that first window.

How can I name that window or use another method to indicate that this is the start point?

Thank you in advance

Hey Lloyd,

That's easy enough, but you have to use AppleScript.

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/04/18 15:09
# dMod: 2021/04/18 15:09 
# Appl: Google Chrome
# Task: Execute JavaScript in a Specific Tab
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Google_Chrome, @Execute, @JavaScript
--------------------------------------------------------

set jsCmdStr to "

   document.URL

"

doJavaScriptInChrome(jsCmdStr)


tell application "Google Chrome"
   set activeTab to the active tab of the front window
   
   tell activeTab
      set jsOutput to execute javascript jsCmdStr
   end tell
   
end tell

--------------------------------------------------------

You can also do this in Safari, although the syntax is a bit different.

-Chris