Applescript - Google Chrome activate a certain window

前端 未结 6 1539
梦毁少年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 21:59

    if you run this

    activate application "Google Chrome"
    tell application "System Events" to keystroke "`" using command down
    

    it will do the whole thing even if its run from script editor.

    heres another way, this one was already spelled out by someone else just in more steps:

    tell application "System Events" to tell process "Google Chrome" to perform action "AXRaise" of window 2
    activate application "Google Chrome"
    

    if youre willing to save it as an application and assign it to a hotkey, you can do this:

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

    though i suppose at that point you may aswell simply hit command+`. Unless of course, your applescript involves a series of steps creating a series of steps, as is likely the case. If it involves a series of steps, something like the first line of the second code sample would be all you'd need, provided you assign it to a hotkey and hit the hotkey when chrome is already activated (or the line comes after chrome is activated in your code).

提交回复
热议问题