1

I'd like to have a script that gets some input on one Chrome window, switches to another Chrome Window to process it, and then returns to the original window.

I can get the Chrome window title from the original window, process on the second window, but I'm failing to return to the original window.

this is the working code to get the Window title:

my getCurrentWindowTitle()

my returnToOriginalWindow()

global frontApp, frontAppName, windowTitle

set windowTitle to ""

on getCurrentWindowTitle()
    tell application "System Events"
        set frontApp to first application process whose frontmost is true
        set frontAppName to name of frontApp
        tell process frontAppName
            tell (1st window whose value of attribute "AXMain" is true)
                set windowTitle to value of attribute "AXTitle" 
            end tell
        end tell
    end tell
end getCurrentWindowTitle

And this is the code bit which I'm struggling to tweak so I can return to the original window:

on returnToOriginalWindow()
    tell application "Google Chrome" to set index of window 1 where title contains windowTitle to 1
    delay 0.05
    do shell script "open -a Google\\ Chrome"
end returnToOriginalWindow

Any insights on how to test, develop, fix this are really appreciated.

1
  • I don't use chrome but in vivaldi you can do something like properties of windows, which returns a list of lists, including id, index and name. Perhaps chrome has similar functionality. With that, you should be able to bring any window to the fore.
    – Mockman
    Commented Jan 11, 2022 at 14:55

1 Answer 1

0

One possible solution: you trim a part of the Window Title name:

   on returnToOriginalWindow()
    set the_short_name to characters 1 thru 20 of windowTitle as string
    tell application "Google Chrome" to set index of window 1 where title contains the_short_name to 1
    delay 0.05
    do shell script "open -a Google\\ Chrome"
end returnToOriginalWindow

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .