MacOS – How to focus a specific window with applescript without doing an activate and bringing other windows to the front

applescriptmacos

I'm looking for a method w/ AppleScript to select/focus a specific window of an application without actually doing an "activate" which brings all windows to the front.

Here's what I have so far:

tell application "Google Chrome"
    set windowTitle to title of first window whose title contains "whatever"
end tell
tell application "System Events" to tell process "Google Chrome"
    click menu item windowTitle of menu 1 of menu bar item "Window" of menu bar 1
end tell
tell application "Google Chrome" to activate    

The problem is the "activate" in the last line. That brings everything to the front, but I just want the one window.

Best Answer

You're right that the activate command raises all windows. The open shell command only raises one window though:

tell application "Google Chrome" to set index of window 1 where title contains "whatever" to 1
delay 0.05
do shell script "open -a Google\\ Chrome"