Monday, December 18, 2017

#1 2017-02-25 09:36:08 am

Riku
Member
Registered: 2016-05-23
Posts: 27

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.

Offline

 

#2 2017-02-25 11:07:59 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4458

Re: Always force AppleScript app dialog windows to top?

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.

Applescript:

tell me to activate
display dialog "blah blah blah"

… or …

Applescript:

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


NG

Offline

 

#3 2017-05-31 06:30:13 am

Riku
Member
Registered: 2016-05-23
Posts: 27

Re: Always force AppleScript app dialog windows to top?

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. big_smile
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. hmm

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?

Last edited by Riku (2017-05-31 06:30:42 am)

Offline

 

#4 2017-07-30 09:18:48 am

sharkbone
Member
Registered: 2016-01-28
Posts: 12

Re: Always force AppleScript app dialog windows to top?

You can do this actually if you do it from within bash using osascript.
Try opening up the Terminal.app and typing:

 osascript -e 'display dialog "Hello World!"'

You could make it even easier on yourself by creating a function like:

dialog(){
  osascript -e 'display dialog "Hello World!"'
}

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:

Applescript:

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.

Offline

 

#5 2017-07-31 04:19:28 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4458

Re: Always force AppleScript app dialog windows to top?

Riku wrote:

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?


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.

Applescript:

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


NG

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)