quit problem

This is a portion of a much larger script ªsaved as app with stay open option) that works
perfectly EXCEPT when the script presents the user and password dialog box with the mount command and the user clicks the cancel button instead of entering their password and mounting the volume. I have tried every variation I can think of, and
the script just won’t recognize the quit statement at the end of the try routine.
What the HECK am I doing wrong? I’m sure it’s something really stupid!

on run
if (loginname as string is "") then
tell application "Finder"
display dialog "login name is not defined--quitting program" buttons {"ok"} default button 1
end tell
quit
--this quit command WILL properly invoke the quit handler
else
try
tell application "Finder"
mount volume "foo" on server "bar" in AppleTalk zone "snafu" as user name loginname with password ""
end tell
--if user cancels above login then the on error should run
on error
tell application "Finder"
display dialog "login cancelled--quitting program" buttons {"ok"} default button 1
end tell
---on a cancel the above works, I get the dialog
quit
--but this quit command does NOT invoke the quit handler and rest of script tries to continue running
end try
tell application "Finder" --yada yada yada
-----rest of the script-------
end if
end run
on quit
continue quit
end quit

This may be off base, but… try naming your quit handler with a different name than quit. You may have given it a reserved name used by some scripting addition. Though you should be able to see this if you have ‘formatting’ set with colors.
Just a thought. Don’t have time to test.

Ask the super-pros on the mailing lists, either Applescript Users or MacScript Digest. Sign up at Apple’s web site.
macguy

Hey, Shannon
Whenever I have problems getting a script to quit, I use the tried and true
error number -128
This, of course, is the error returned when a user cancels. It works perfectly to quit a script at any point.
So, in your example, you could capture the user response and quit the script thusly:

set theReply to (display dialog "login cancelled--quitting program" buttons {"ok"} default button 1)
set theButton to button returned of theReply
if theButton = "ok" then
error number -128
end if

Yeah, it’s a bit of extra coding, and yeah, a quit handler looks a lot spiffier, but the above will quit your script.
cheers!

It’s just Jim again, editing out your original message, so you could find my response

Here’s the script:


on quit
	
	tell application "Finder"
		activate
		beep
		
		set dd to display dialog "Your Excel Spreadsheed has finished calculating." & return & return & ¬
			"Do you wish to save it?" giving up after 120 with icon stop ¬
			buttons {"Yes", "No"} default button "No"
		
		if (gave up of dd is true) then
			set response to "No"
		else
			set response to button returned of dd
		end if
	end tell
	
	tell application "Microsoft Excel" to activate
	
	if (response is "Yes") then
		tell application "Microsoft Excel"
			-- set filePath to path to me
			-- display dialog filePath as string
			-- save workbook as active workbook filename filePath
    
			save workbook
		end tell
	end if
	
	error number -128 -- when the user cancels
	-- continue quit
	
end quit

If I use continue quit, rather than error number, the droplet will not quit and generates a “Connection is invalid” error. If I use the error number approach, my on quit handler does save the Excel worksheet and my droplet is quit with no “Connection is invalid” error.

However, my on quit handler executes TWICE. Halp!!