Applescript - Bring window to foreground

Giorgio picture Giorgio · Nov 1, 2012 · Viewed 32.4k times · Source

I have an application with several windows opened at the same time. I'd like to bring a specific window to foreground (I know its title).

At the moment I'm using a combination of keys to achieve this task but I'd like to try something different since I'm experiencing some problems with this approach.

tell application "System Events"
    set frontmost of process "appIT" to true
    keystroke "1" using command down
    delay 0.2
end tell

Answer

jackjr300 picture jackjr300 · Nov 1, 2012

This is possible by using the "AXRaise" action, except on certain window (applications that use X11 for example).

Try this.

set theTitle to "some title"
tell application "System Events"
    tell process "appIT"
        set frontmost to true
        perform action "AXRaise" of (windows whose title is theTitle)
    end tell
end tell