Ok, I realize this is asking for the impossible. I habitually have about 4 Chrome windows open. On linux, I have a system set up so I have a different keyboard shortcut to switch to each window, so I can jump to the correct one really quickly.

Is there possibly a way to do this on OSX? I'm willing to write moderate amounts of code if necessary to implement this, 'though I should probably head over to StackOverflow if that looks like it will be needed.

  • How would you identify the windows or decide which one to focus? Do you keep them on different spaces or something?
    – Lri
    Oct 6, 2012 at 6:29
  • No, not difference spaces. Some other attribute of the window might be possible, though, like the order in which they were created. That's the way it works on linux. Oct 6, 2012 at 16:52
  • How about creating a macro which would select the Window menu and then click at (X,Y) for the window you want?
    – Tuesday
    Oct 6, 2012 at 19:35

1 Answer 1

    set text item delimiters to linefeed
    tell application "Google Chrome"
        do shell script "sort -n <<< " & quoted form of (id of windows as text) & " | sed -n 3p"
        set w to window id (result as integer)
        set b to bounds of w
        set t to title of w
    end tell
    tell application "System Events" to tell process "Google Chrome"
        window 1 where position is {item 1 of b, item 2 of b} and title is t
        perform action "AXRaise" of result
        set frontmost to true
    end tell
end try

Windows that were created later usually have a larger id. If the script is run when there's no second window, there won't be an error dialog because it's wrapped in a try block.

You can give the scripts shortcuts with FastScripts or by creating Automator services.

  • Thanks a ton! This is exactly what I wanted. I ended up calling out to a custom python script instead of using UNIX utilities, but this is pretty much what I'm now doing. Oct 12, 2012 at 6:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .