Keyboard shortcut to switch to a specific Chrome window

google-chromekeyboard

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.

Best Answer

try
    set text item delimiters to linefeed
    tell application "Google Chrome"
        reopen
        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.