title: Set focus to specific window of an application using applescript
body: <p>How can I set focus to a specific window of a given application using applescript?</p>
  
  <p>I have several iTerm2 windows running on different displays. I want to set focus to a specified window using applescript.</p>
  
  <p>I need two things, one script that collects the window ID's and prints them to stdout. I've got this:</p>
  
  <pre><code>tell application "iTerm"
    set wins to id of every window
  end tell
  </code></pre>
  
  <p>which prints 6 integers: 3034, 2528, -1, -1, -1, -1</p>
  
  <p>Bonus Question: What are the four -1's ?</p>
  
  <p>Then I try:</p>
  
  <pre><code>tell application "System Events"
    activate window 3034
  end tell
  </code></pre>
  
  <p>Upon which the only thing happening is that I lose focus of my current terminal (in which I am typing these commands), not matter whether I specify 3034 or 2528 as the ID.</p>