An AppleScript to bring the iOS Simulator to the foreground

I use BetterTouchTool to bind apps to shortcut keys (similar to the way Brett Terpstra does). For example, pressing ⌘⌥⌃⇧-X brings up Xcode. Actually I have ⌘⌥⌃⇧ bound to the caps lock key. This way I can press caps lock-X to bring up Xcode. I have my most common apps bound to shortcut keys. I rarely use ⌘-tab now. Much faster.

I used to have the caps lock bound to the control key, but having an app switcher/system key has been much more useful on the Mac.

I wanted to be able to bind the iOS Simulator to a key, but there are several simulators and Xcode versions on machine. Every time I would try to bind a key to the Simulator a different Simulator would pop up. So I created the below AppleScript to bring the Simulator to the foreground.

tell application "System Events"
  set theProcesses to application processes
  repeat with theProcess from 1 to count theProcesses
    set theName to (name of process theProcess)
    if theName contains "Simulator" then
      tell process theProcess
        set the frontmost to true
      end tell
    end if
  end repeat
end tell