confirming a quit dialog

I’m trying to write a simple script to quit an application (Democracy). But sometimes (if it’s in the middle of downloading something) it brings up a confirmation dialog that asks if I really want to quit, with the options Cancel and Quit. Quit is the default button, if that matters. Is there a way to add some applescript that selects Quit from the confirmation diaolog, if that dialog appears?

Hopefully that makes sense and thanks in advance for your help with what I’m sure is a very basic question.

Thanks,

scott

Hi Benishs

Something like this may work you’ll have to give it a try you will have to
add this to a currently running script for democracy otherwise theres no point you may aswell click return to quit the app
manually:

tell application "System Events"
	tell application process "Democracy"
		set frontmost to true
		keystroke return
	end tell
end tell

Hi Scott,

you can use a forced timeout error,
and press the button with UI scripting,
here an example with TextEdit:

try
	with timeout of 10 seconds
		quit application "TextEdit"
	end timeout
on error number e
	if e is -1712 then
		activate application "TextEdit"
		tell application "System Events"
			tell application process "TextEdit"
				click button "Cancel" of sheet 1 of window 1
			end tell
		end tell
	end if
end try

Thanks for the quick response and the suggestions.

Pidge1, I tried what you suggested and it sat there for awhile not doing anything and then eventually the script editor gave me:
AppleScript Error
Democracy got an error: AppleEvent timed out.

Stefan, I tried your script, replacing “TextEdit” with “Democracy” and “Cancel” with “Quit”. It issues the quit command (which makes Democracy bring up the Quit confirmation dialog), and it also brings the Democracy app to the front but it doesn’t actually quit and the script editor gives this error:
AppleScript Error
System Events got an error:
NSReceiverEvaluationScriptError: 4

Any other ideas?

Thanks for the help,

scott

Looks like I replied too soon - I was able to hack together something that seems to work by combining the 2 suggestions. I replaced this line from Stefan’s script:
click button “Cancel” of sheet 1 of window 1

with:
keystroke return

and it works!

thanks for the help.

scott