Ignoring Display Dialog

I am wondering if there is a way to have Applescript totally ignore the contents of a dialog box, rather than beeping at you and requiring user attention before it will go on.

I am using a display dialog box to periodically display information but do not require any user input.

Works fine provided the application to which the display dialog is attached (iTunes) remains in front. But if the user switches to another app while the script is working away, the computer will beep and bounce the iTunes icon and require the user to switch back, before it will carry on.

Here is the script I am using:


if (current date) - thirtySecupdate > 30 then
ignoring application responses
display dialog (trackCount as string) & " of " & (songs_selected as string) & " processed …" buttons “OK” default button 1 giving up after 3
end ignoring
set thirtySecupdate to (current date)
end if


Including the “ignoring application responses” does not seem to help in any way. Although I had thought that it would.

Is what I want to do achievable?

Thanks

The only way I’ve found is to use an alternative notifier: FastScripts, Growl, LanOSD and several others.

This may work as well, but not a very UI-friendly method:

ignoring application responses
	tell application "System Events" to display dialog "foo" giving up after 10
end ignoring

I don’t get a dialog if I do this in 10.4.4 (not even if I stay in the script editor), but leaving the tell statement out doesn’t stop the SE bounces in the dock. Ugh. If you’re running the script from the editor, this works by popping the dialog up in front, but of course that loses focus on where you were:

delay 3 -- time to switch away to something else
tell application "Script Editor" to activate  -- goes back
display dialog "Foo" giving up after 5

Thanks for all the suggestions

I tried Jacques’ work around which should have worked but which in the end resulted in the same problem - bouncing iTunes dock item and a beep whenever I was in another app and the dialog prompt was activated by the script.

I have no idea why it should act this way as running Jacques’ script as a stand alone item will always deliver the dialog in the currently active app (as its contents suggest it will do).

However (as a debugging test), if I set my itunes script running (disabling the dialog prompt script inside the main script), then run Jacques’ script concurrently as a standalone item, switching to iTunes will not produce a dialog box from Jacques’ script - which simply times out after 120 seconds.

Hi,

If you have Smile, here’s an example of making a Smile dialog with just a text field for viewing, by script.

using terms from application “Smile”
property window_props : {class:dialog ¬
, name:“new dialog”, visible:true ¬
, resource id:131 ¬
, bounds:{100, 100, 700, 500} ¬
, text font:“Monaco”, text size:9 ¬
, «class Rect»:{0, 0, 0, 0} ¬
, message height:0 ¬
, requested user level:0}
property text_props : {class:dialog item ¬
, control kind:272 ¬
, bounds:{20, 20, 580, 360} ¬
, font:{font:-1} ¬
, contents:“hello”, call script:true ¬
, enabled:false ¬
, «class Auto»:false}
end using terms from
global d, di, c

on run
tell application “Smile”
launch
activate
set d to (make new dialog at front with properties window_props)
set di to (make new dialog item at d with properties text_props)
end tell
set c to 0
end run

on idle
tell application “System Events”
set process_list to (name of every process)
end tell
if “Smile” is in process_list then
set c to c + 1
try
tell application “Smile”
set properties of di to {contents:(c as string)}
end tell
on error – no window
quit
end try
else – no Smile
quit
end if
return 30
end idle

on quit
tell application “System Events”
set smile_running to (exists process “Smile”)
end tell
if smile_running then
tell application “Smile” to quit
end if
continue quit
end quit

Smile:

http://www.satimage.fr/software/en/smile_doc.html

Editted: BTW, most of the properties of the window and text is default and not necessary. I just copied it from the Smile worksheet.

gl,

Thanks, Jacques. By taking it out of the main iTunes loop, it all works as you’d expect. Just a shame you can’t have it pop up only in iTunes , rather than leaping out at you wherever you happen to be.

Terrific.

Kel, thanks for the Smile advice as well but I don’t have Smile and am hoping to avoid as many add on bits as possible. I hope to have a closer look at Smile, however, if I can.

Cheers

One last comment which may help. I found that I was getting problems if (for example) I was in a prompt box in another application (eg choosing a file to open) at the moment that the script tried to pop up its dialog box. The script would freeze, timeout and give up.

So I added some timeout and try code.

Finished handler (with ability to capture if cancel clicked for the purposes of my script):


on displayINFO(trackCount, songs_selected)
	tell application "System Events" to set FRontApp to name of (first application process whose frontmost is true)
	try
	set cancel_test to false
		with timeout of 3 seconds
			tell application FRontApp to display dialog "CAPITALIZE SELECTED TAGS" & return & return & (trackCount as string) & " of " & (songs_selected as string) & " tracks processed ..." buttons {"Cancel", "OK"} default button 2 giving up after 3
		end timeout
	on error number errorNumber
		if errorNumber = -128 then set cancel_test to true
	end try
	return cancel_test
end displayINFO


Thanks for the suggestion, Jacques

I have an Astudio app but just wanted to make the script run without it, if the user chooses. If the script does not have to update the app to show progress, it runs around 50% faster.

Merci

So do you want it to display the dialog only if the user is still in iTunes? If the frontmost application is something else, the dialog shouldn’t be displayed? If that is the case, try something like this:

tell application "System Events" to set FRontApp to name of (first application process whose frontmost is true)
if FRontApp = "iTunes" then
   tell application FRontApp to display dialog (trackCount as string) & " of " & (songs_selected as string) & " processed ..." giving up after 3
end if

Thanks Sälli. Just what the doctor ordered. Now if the user switches out of iTunes it processes at full speed.