I am trying to write an AppleScript to periodically backup 6 active folders (e.g. MAIL, AddressBook, etc) to a 512 MB flash drive.
I have included the “with replacing” instruction, at the end of the “select folder” line, which is accepted by Syntax. At the end of the “copy” line, Syntax does NOT accept it.
When I run the script, it runs through, but I get “AppleScript Error - Finder error. An item with the same name already exists in the destination.”
I know that ! That is why I added “with replacing”…
No problem. Please post your code here and someone can probably point out the issue quickly. Be sure to use the nifty Applescript brackets to enclose your script; that makes it easier for everyone else to read, and open it for examination and testing.
tell application "Finder"
activate
select disk "512 HD"
open selection
select startup disk
open selection
select folder "AddressBook" of folder "Application Support" of folder "Library" of folder "robertww" of folder "Users" of startup disk with replacing
duplicate selection to disk "512 HD"
end tell
The “with replacing” instruction just does not seem to be working.
Can some genius help me ???
WW
Model: iBook
AppleScript: Script Editor 2.0
Browser: Internet Explorer 5.2.3 (5815.1)
Operating System: Mac OS X (10.3.9)
Thanks for including your script, WW. As Craig mentioned, this makes it much easier to work out the nature of a problem - as well as (hopefully) a solution.
There may be a few issues possibly worth exploring here. For this kind of situation, many of the Finder actions in your script (activate, select and open) aren’t strictly necessary. Finder will quite happily do your bidding without them.
In addition, the replacing parameter is relevant to only two Finder commands: move and duplicate. (If in doubt, you can always check an application’s AppleScript dictionary for information like this.)
Finally, it’s usually a good idea to write your script in a way that refers to file/folder paths more generally - which could make the script more useful to other users (and might even avoid problems if changes to the system architecture are made at any point in the future).
Here’s an alternative for you to try, as an example:
set sourceFolder to (path to application support from user domain as Unicode text) & "AddressBook"
tell application "Finder" to duplicate folder sourceFolder to disk "512 HD" with replacing
For several folders, you might try something like the following version. (Add any other items to the list as required - relative to your library folder.)
set libFolder to (path to library folder from user domain as Unicode text)
tell application "Finder" to repeat with sourceFolder in {"Application Support:AddressBook", "Mail"}
duplicate folder (libFolder & sourceFolder) to disk "512 HD" with replacing
end repeat