How would I Activate a window using its Window index on applescript?

I open two windows of vscode , now I want to activate vscode with specific index or name .

I don't know how to write the script .

tell application "Google Chrome" to set index of window 2 to 2
delay 0.05
do shell script "open -a Google\\ Chrome"

it work with chrome ,but dont work with visual studio code .

Accepted Answer

It looks like Visual Studio Code doesn't have an AppleScript dictionary, so perhaps use System Events?

tell application "System Events"
	tell process "Code"
    -- selecting window to raise by its title, modify as needed
		set w to item 1 of (windows whose title is "Untitled-1") 
		perform action "AXRaise" of item 1 of w
	end tell
	activate application "Visual Studio Code"
end tell
How would I Activate a window using its Window index on applescript?
 
 
Q