Set focus to specific window of an application using applescript

前端 未结 1 562
遥遥无期
遥遥无期 2021-02-09 01:47

How can I set focus to a specific window of a given application using applescript?

I have several iTerm2 windows running on different displays. I want to set focus to a

相关标签:
1条回答
  • 2021-02-09 02:09

    You almost have it. You can filter out the "-1" window IDs as by only looking at visible windows:

    tell application "iTerm 2"
      set wins to id of every window whose visible is true
    end tell
    

    I figured this out by looking at the results of:

    tell application "iTerm 2" to properties of every window
    

    I noticed that the "-1" windows have the property visible:false

    Then you can tell the window ID directly to the iTerm application instead of system events:

    tell application "iTerm 2"
      activate window 13195
    end tell
    
    0 讨论(0)
提交回复
热议问题