Quitting script when administrator password is entered wrong 3 times.

Hi guys,

How do you catch the result of a user entering an invalid password three times in the administrator box, so I can shut down the script? Also, if the user hits cancel on the administrative dialog box, it should end the script as well. But I can’t use “button returned of” in this instance…I already tried.

Please help.

Thanks and God Bless.

Ben.

The security agent does the three-times-try for you,
you have only to filter the different errors


try
	do shell script "echo ''" with administrator privileges
on error number n
	if n is -128 then
		display dialog "User cancelled"
	else
		display dialog "Dismissed"
	end if
end try

Thanks dude! :slight_smile:

God Bless :slight_smile:

Oh, one more thing…is there a way to retrieve the actual error when a file to be deleted is missing?

such as on error exists file

if file is false
then quit

I’m asking this because the on error code snippet you gave me before just tells me when a -128 is passed, I want to check if a file is not there.

Thanks.


try
	
	--when something fails... for instance:
	
	tell application "Finder"
		open file "Foo" of the desktop
	end tell
	
	--then show the specific error and message...
	
on error errorMsg number errorNum
	display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end try

Peter B. (The Devil Incarnate)



try
	do shell script "rm -r ~/Desktop/qwertzuio" with administrator privileges
on error number n
	if n is -128 then
		display dialog "User cancelled"
	else if n = 1 then
		display dialog "File doesn't exist"
	else
		display dialog "Dismissed"
	end if
end try

Thanks so much dude! :slight_smile: What’s the significance of integer 1?

Or you could check the files existence prior to the authentication request so you aren’t making the user waste a step.

Nothing to see here… look at Mr. Quotes the Man Page’s answer below!

<3 ya Stefan :smiley:

from the rm man page:

The rm utility exits 0 if all of the named files or file hierarchies were
removed, or if the -f option was specified and all of the existing files
or file hierarchies were removed. If an error occurs, rm exits with a
value >0.

Cool, works beautifully now! :slight_smile:

Thanks again for your help guys.

God bless you all! :slight_smile:

Ben.

Way to go and be specific, sigh… now I have to go adjust my answer

::shakes fist::

.
.
.
.
.

=)