OS X: is it possible to open a window on top with AppleScript?

Solution 1:

Use tell application "name" to activate, where name is the name of the application you want brought to the front. If you already have a tell statement block for the target application you can use activate by itself within the tell statement block.

Examples:

tell application "name" to activate

Or:

tell application "name"
    activate
    # Other commands to follow...
end tell

Also, if the target app is being opened from within a shell script, whether executed manually in Terminal or within AppleScript e.g. do shell script "name.sh ..." you can add an AppleScript command within the shell script using osascript as in the following:

Syntax:

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

Example:

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

Note: In Terminal, type man osascript and press enter, to display the BSD General Commands Manual entry for osascript.


From the AppleScript Language Guide:

activate


Brings an application to the front, launching it if necessary.


As a good reference, have a look at Introduction to AppleScript Language Guide and the following document is handy to have on your system, AppleScript Language Guide (2013) PDF.