While developing for the web I tend to jump back and forth between my text editor and the browser a lot. I'd like to set a keyboard shortcut at the OS level that allows me to jump to a specific, definable window every time. Even better would be the ability to issue a tell that application to execute something, but I'll save that for later.

Are there technologies available that will let me do this? There must be something between C and AppleScript that let's me create this kind of an interaction. Does anybody know where to begin?



You should give Automator a try. You could "Record" a new service (that you can later publish for all Apps and assign a Keyboard Shortcut), that clicks the app from the Dock. In fact, you could add more actions and perform your "tell that application to execute something".

I've tried creating one (that is relatively useless but works) that clicks on Mail in my Dock, then clicks the get new mail icon in the toolbar. Fun ;)

Attached is the shot of the Automator result:


I used the Record button on the top right corner and then did the actions myself (clicked on the Mail's dock icon, then clicked on Mail's Get New Mail icon in the toolbar, then clicked "Stop Recording"). Please notice I've selected "Service receives [no input]" in the first combo box, as I wasn't interested in any input.

This gives you multiple possibilities to have a couple of services that go back and forth your TextEditor and your Browser.

Automator is located by using Spotlight and typing Automator (also located in /Applications/Automator.app)

In this case I've created a new "Service" but you could probably get away by creating "scripts". Not sure which one would be faster tho. Experiment. Automator is your friend.


You might do something like this with AppleScript:

tell application "Terminal"
    windows where name contains "bash"
    if result is not {} then set index of item 1 of result to 1
end tell

Or using System Events:

tell application "System Events" to tell process "Terminal"
    set frontmost to true
    windows where title contains "bash"
    if result is not {} then perform action "AXRaise" of item 1 of result
end tell

I use BetterTouchTool for setting different keyboard shortcuts or trackpad gestures on Mac OS X. One of the actions it can launch is Execute Terminal Command

So in the settings of the command I provide following:

osascript -e 'tell application "NameOfTheApplicationHere" to activate'

Here is an example from the BetterTouchTool preferences:

enter image description here


I had a lot of trouble getting this to work with iTerm2. Here is single command solution:

  osascript -e 'tell application "System Events" to tell process "iTerm2"' \
            -e 'set frontmost to true' \
            -e 'if windows is not {} then perform action "AXRaise" of item 1 of windows' \
            -e 'end tell'

You must log in to answer this question.

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