Is Users/username/Library folder somehow magic?

Hi!

I’m trying to write a little AppleScript to automatically backup my home directory every night. I’m a software developer, but I have no experience at all with AppleScript. I’m having some trouble and I’d really appreciate some words of wisdom.

I’ll attach the (short) script itself to the end of this message, but I’ve narrowed my sitch down to this:

First: when I try to copy the “Library” folder (from inside my Users/username folder), I get: “Finder got an error: An item with the same name already exists in the destination” even though the destination is a folder that I create (new & empty) on an external drive.

I’m guessing that the system is creating some special invisible file somewhere in the process. Q1: Any idea what or why?

Second: when I append “replacing conflicts” to the “duplicate” command, the system pops up a dialog while the script is running that asks me for my password. Q2: Any idea why? (I’m surprised that I’m doing anything perceived as authentication-worthy; I’m just copying my own files.) Also, how/where would I specify my username and password?

Thanks very much in advance. I thought this would be a very straightforward introduction to AppleScript but I’ve apparently started down a path littered with odd special cases. Thanks for your help!

(script follows)


tell application “Finder”

set hostFolder to folder "AppleScripted Lando bpus" of disk "DS160" -- where to put the created serialized bpu folders
set userToBackup to folder "lando" of folder "Users" of disk "Lando" -- which user folder to backup
set newFolderName to "new backup folder"

set newFolder to make folder at hostFolder with properties {name:newFolderName}

duplicate folder "Library" of userToBackup to newFolder
-- duplicate folder "Library" of userToBackup to newFolder replacing conflicts

end tell

According to Script Editor’s event log, the ‘duplicate’ line returns ‘document file “Library”’ just before throwing the “item already exists” error. ‘List folder’ doesn’t reveal this file though. It seems to be some artifact unique to moving the Library folder. Strange.

I’ve never heard of ‘replacing conflicts’, though it seems to compile in OS 10.2.8. If I use the more conventional ‘with replacing’, the script works fine.

Great!

I switched to ‘with replacing’ and it sails right along.

Thanks!