Bring display enhanced alert to the front

I am trying to bring the display enhanced alert (thanks Shane for this library!!!) to the front without success: it is part of a Folder Action script

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.0"

on adding folder items to this_folder after receiving these_items -- this_folder is an alias
	get every item of these_items -- as file
	repeat with NewFiles in result
		tell application "Finder"
			tell file NewFiles
				set theMessage to "Shoud I move " & name & " to iMac Downloads folder?"
			end tell
		end tell
	
		tell me to activate
		set all_parameters to display enhanced alert theMessage message "" buttons {"No", "Trash Me", "Show me the file", "Yes"} acc view width 320 acc view height 32 acc view controls {}
		set the user_choice to the item 1 of all_parameters -- button returned of the result
	end repeat
end adding folder items to

I also tried with:
tell application “System Events” to activate
tell application “Finder” to activate
tell current application to activate
tell application “ScriptMonitor” to activate
tell application “FolderActionsDispatcher” to activate

Any suggestion?

I suspect it can only respond to current application, but the problem is really the display limitations of the app that runs folder actions. I don’t know that you’ll find a perfect solution.

Which is the the app that runs folder actions?
I tried to find out but I couldn’t …

I’m not sure. Try doing something like ‘display dialog (get name of current application)’.

wow!
I didn’t taught about that !
I checked and it is “osascript”
I will check if it responds to commands sun as “activate”

Thanks

I can’t activate osascript since is not an application but a “Unix executable”
Too bad …

I’m not sure this will work, but try it yourself:


tell me
	activate
	set all_parameters to display enhanced alert "BlaBla" message "" buttons {"No", "Trash Me", "Show me the file", "Yes"} acc view width 320 acc view height 32 acc view controls {}
end tell

Maybe I’m missing something here, but if you just want to be sure the dialog displays in the frontmost app so it doesn’t “pop-under” without focus, can’t you just tell the Finder to activate and then do the “display enhanced alert” inside a Finder tell? It seems to me like it shouldn’t matter much which app you choose, just pick any application that you know you can activate and have it show the dialog.

I tried. Didn’t work.

The finder is the front application.
The Dialog window is at the top, but has no focus.
What I mean is the preferred button (“Yes”) is not blue, but grey like the others.
If I click on the topbar (or anywhere else in the window) then it really comes in the front, it gets the focus, and the “Yes” button become blue.

No. The dialog belongs to whatever process is running the script.

  1. Application process “osascript” exists. 2) Display dialog appears always at certain position of screen.

So, you can use some mouse tool and click display dialog in “System Events” to activate it. Not better solution, but… As I see, process “osascript” is sandboxed process, so I can’t manage it otherway

Hi.

I haven’t tried this with Dialog Toolkit Plus itself, but the idea seems to work in other contexts. Try putting the Dialog Toolkit Plus code in a handler in a separate script, like this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use script "Dialog Toolkit Plus" version "1.1.0"

on displayAlert(alertMessage, submessage, bttns, viewWidth, viewHeight, viewControls )
	activate
	return (display enhanced alert theMessage message submessage buttons bttns acc view width viewWidth acc view height viewHeight acc view controls viewControls)
end displayAlert

Save this script somewhere convenient as a stay-open application. (I’ve assumed the name “Enhanced Displayer.app” for it, but of course you can use whatever you prefer.) This script will be run by its own application code rather than by the folder action application, so it should have no problem displaying the dialog.

The folder action script would then communicate with it something like this:

on adding folder items to this_folder after receiving these_items -- this_folder is an alias
	-- Prepare the stay-open helper script.
	tell application "Enhanced Displayer" to launch
	
	repeat with NewFiles in these_items
		tell application "Finder" to set thisName to name of thisFile
		set theMessage to "Shoud I move " & thisName & " to iMac Downloads folder?"
		
		tell application "Enhanced Displayer"
			set all_parameters to displayAlert(theMessage, "", {"No", "Trash Me", "Show me the file", "Yes"}, 320, 32, {})
		end
		set the user_choice to the item 1 of all_parameters -- button returned of the result
	end repeat
	
	-- Quit the stay-open script when finished.
	tell application "Enhanced Displayer" to quit
end adding folder items to

Thanks Nigel! Walking back home I was thinking about something similar.
I will work on this direction.
It seems a small glitch of the display enhanced alert, since the classic Display dialog appear in front and with the proper focus.
I am trying to circumvent this little problem since it is so useful to have more than 3 buttons …

@KniazidisR: your “click” idea I don’t think that will work.
The “Click” code should be right after the the display enhanced alert code.
But, the script will wait for the user to choose the button before executing the next script line (click on a specific location).
And my point was to be able to choose the default button just by pressing the return key, but I can’t since it is grey …

But, thanks everybody for the feedback!

It worked very smoothly …

Thanks !