Always force AppleScript app dialog windows to top?

The title pretty much explains the question already: When running an independent AppleScript application outside of Script Editor, is there a way to make the dialogs windows of the script always appear on top of all other application windows?

I frequently run scripts from the script menu casually and especially if they have multiple dialog windows, any dialog after the first one tends to appear behind other windows (such as internet browser etc.), so I’ll have to click its jumpy application icon in the Dock to bring it visible. I’ve allowed keyboard navigation (tab and enter) for many of the dialogs so I wouldn’t have to use the mouse to click the buttons, but this visibility issue breaks the flow.

Hi Riku.

Either the application running the script has to be frontmost when the dialog’s displayed or the application which happens to be frontmost at the time has to be told to do the displaying.

tell me to activate
display dialog "blah blah blah"

. or .

tell application (path to frontmost application as text)
	display dialog "blah blah blah"
end tell

Oops, seems like I got unexpectedly busy and then forgot, now came back to wonder, “didn’t I already ask about this somewhere…?” Indeed, I did. :smiley:
For some reason ‘subscribe to this topic’ wasn’t ticked either.

For some reason, neither of your suggested methods yielded any different results; If I for example have Safari open, then from the scripts menu in the top right, I launch the script application that I want to do its thing in the background until it ends with a dialog window, still this:
-The script app in question opens up in the dock but doesn’t become visible except for the fact that the text “Safari” in the top left corner of the screen is replaced by the title of the script app
-When finished, the script app’s dock icon jumps because it has reached its verdict, and I need to click it in order to bring the dialog window foremost. :confused:

In a way, if the script app’s name is displayed in the top left corner in the menu bar, doesn’t that indicate that it is foremost or at least active?

You can do this actually if you do it from within bash using osascript.
Try opening up the Terminal.app and typing:
[format] osascript -e ‘display dialog “Hello World!”’[/format]

You could make it even easier on yourself by creating a function like:
[format]dialog(){
osascript -e ‘display dialog “Hello World!”’
}[/format]

You could then call the function by simply typing dialog or whatever name you choose from within the Terminal.

If you wanted to do this from AppleScript Editor:

do shell script "osascript -e 'display dialog \"Hello World!\"'"

The last method seem a little redundant in my opinion as you’re basically telling the shell to call applescript from applescript. Not to mention that this sort of construct can become a quoting nightmare real quick. But it does work.

Not necessarily. It means it’s the frontmost visible process having a menu bar. If something happens while it’s running to bring an invisible process to the front, the script app’s name will still be in the menu bar and the script will still think it’s the frontmost application, but it’ll actually be behind the invisible process and unable to show a dialog.

tell application "System Events" to activate -- Bring an invisible process to the front.

tell application (path to frontmost application as text)
	say "The frontmost application is " & (get its name)
	say "Its frontmost is " & (get its frontmost)
	tell application "System Events"
		set p1 to name of first process whose frontmost is true
		set ap1 to name of first application process whose frontmost is true
	end tell
	say "The frontmost process is " & p1
	say "The frontmost application process is " & ap1
	-- activate -- Uncomment to bring the frontmost application back to the front.
	display dialog "blah blah blah"
end tell

Simple solution from me:


tell application "Safari" to activate

tell current application
	activate
	display dialog "This is myfaceless App's dialog"
end tell