Re: If/Then Statements
Re: If/Then Statements
- Subject: Re: If/Then Statements
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 26 Jan 2010 10:37:21 -0500
The rm command signals an error if asked to remove something which
doesn't exist. If you want to ignore that error and move on, the
usual solution is to pass the -f flag to rm:
do shell script "rm -rf /path/to/some/folder" with administrator privileges
or
do shell script "rm -f /path/to/some/file" with administrator privileges
Alternatively, you can wrap the "do shell script" in a "try ... on
error" block so that it doesn't abort when the shell command signals
an error, but the problem there is that you might miss actual
meaningful errors as well: -f doesn't keep rm from failing if it has
no permission to remove the file, for instance.
Either way, if the list of files to delete isn't significantly larger
than what you sent, you could also do the whole thing as a single
shell command, which would be more efficient:
-- note no quotation marks inside these; we use 'quoted form of' later
set remove_these to { ¬
"/Applications/Utilities/Keychain Minder.app", ¬
"/Library/LaunchDaemons/com.apple.bindad.plist", ¬
"Library/LaunchDaemons/com.apple.migrateaduser.plist", ¬
"/System/Library/User
Template/English.lproj/Library/Preferences/loginwindow.plist", ¬
"/Users/Shared/AD Migration Assistant.app", ¬
"/Users/Shared/prefs.plist" }
set my_command to "rm -rf"
repeat with path_name in remove_these
set my_command to my_command & " " & quoted form of path_name
end repeat
do shell script my_command with administrator privileges
You could also do them one at a time by putting the do shell script
inside the loop - less efficient but still easier to read than a big
long list of nearly identical statements in the source code.
On Tue, Jan 26, 2010 at 10:11 AM, <email@hidden> wrote:
> I am essentially creating a uninstaller script. The script I have works but
> if any element is already gone then it hangs at that point and gives an
> error. I need to put in some kind of if/then statement I believe so that
> when an error is returned it will move to the next line and so on until
> finished. Any suggestions out there would be much appreciated.
>
> do shell script "rm -r /Applications/Utilities/'Keychain Minder.app'" with
> administrator privileges
> do shell script "rm /Library/LaunchDaemons/com.apple.bindad.plist" with
> administrator privileges
> do shell script "rm /Library/LaunchDaemons/com.apple.migrateaduser.plist"
> with administrator privileges
> do shell script "rm /System/Library/'User
> Template'/English.lproj/Library/Preferences/loginwindow.plist" with
> administrator privileges
> do shell script "rm -r /Users/Shared/'AD Migration Assistant.app'" with
> administrator privileges
> do shell script "rm /Users/Shared/prefs.plist" with administrator privileges
>
> ____________________________________________________________________________________________________________________________________
> Jeffrey W. Madson | Macintosh Systems Engineer | RR Donnelley Desktop
> Engineering
> W6545 Quality Drive | Greenville, WI 54942 | Office: 920-997-3768 | Cell:
> 920-915-8619 | Email: email@hidden
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden