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.
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
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
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
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.