Applescript - Google Chrome activate a certain window

前端 未结 6 1542
梦毁少年i
梦毁少年i 2020-12-14 21:42

Do you guys know how to activate the n-th Google Chrome window with Applescript? For example, if I have three Google Chrome windows opened, how do activate the second?

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 22:00

    As mklement mentioned, changing the index raises the window, but for example keyboard shortcuts are still registered by the previously frontmost window.

    tell application "Google Chrome"
        set index of window 2 to 1
    end tell
    

    Another option is to tell System Events to AXRaise window 1:

    tell application "Google Chrome"
        set index of window 2 to 1
    end tell
    tell application "System Events" to tell process "Google Chrome"
        perform action "AXRaise" of window 1
    end tell
    

提交回复
热议问题