I’m trying to write a backup script that will copy various folders (like my Documents folder, and a few others) to my iPod. I first need to check to see if the iPod is there, then I want to replace the folder on the iPod with the source folder from my hard drive. Since I only have a few folders to backup, I don’t mind putting a line item in for each folder to copy. Here is what I have so far (a test line is in now), but it is giving the following error: Finder got an error: Can’t get folder “MacintoshHD/Users/brianflynn/Test Folder”.
tell application "Finder"
if exists disk "Brian's iPod" then
--display dialog "Brian's iPod is ready to use."
move folder "MacintoshHD/Users/brianflynn/Test Folder" to "Brian's iPod" with replacing
else
display dialog "Brian's iPod is not there."
end if
end tell
A few notes about the code. First of all, I used the line that is commented out as a test. When I make it active and comment out the move folder line the exist disk code works fine. So instead of just telling me the disk is there, I decided to have it execute a copy. I have tried “move folder” and “duplicate folder” but still get the error mentioned above. I don’t know what it means that the Finder can’t “get” the folder. (I get the same error when I use a : instead of / in the path name.) I have looked on the BBS here to get some ideas, but have a hard time understanding the logic of some of the coding (I’m new at this). If any one can help I would appreciate it.
tell application "Finder"
if exists disk "Brian's iPod" then
--display dialog "Brian's iPod is ready to use."
set user_ to home as text
duplicate folder (user_ & "Test Folder:") to disk "Brian's iPod" with replacing
else
display dialog "Brian's iPod is not there."
end if
end tell
Thank you Rob for the input. It worked. I have a couple of questions I hope you will address for me.
What did “set user_ to home as text” actually do? I don’t understand the logic behind it.
the code ran, but it asked me to enter by admin password. Is there a way to get around that?
I assume that I can duplicate the duplicate line for any folder under my user directory. what if I want to get a folder from my Applications folder (system level, not user level)?
I ran into another problem with the code. It worked fine on my original test because it copied to root level of the iPod. When I changed the path to copy the folder into a subdirectory it did not work. So I moved all the backup folders to the main directory level and tried with the original code. It will not copy over the existing folder. I get the following error:
Finder got an error: Can’t set disk “Brian’s iPod:” to folder “Macintosh HD:Users:brianflynn:Documents:”.
Any ideas?
P.S. I changed the file name to the Documents folder from Test Folder because that is what I want to backup.
It built a complete path to your user folder. It isn’t necessary but your original script indicated that the hard disk name was “MacintoshHD” and I doubted that it was correct. Using the path to your user folder eliminated doubt.
I don’t know why it’s asking for a password but I suspect that it has something to do with the iPod. Maybe someone else can offer guidance on this.
I suspect that you can duplicate a folder from the Applications folder but I can’t say for certain. This might work after you plug in the name of the subfolder:
set app_folder to path to "apps" as text
set sub_folder to (app_folder & "name of subfolder")
tell application "Finder"
duplicate folder sub_folder to disk "Brian's iPod"
end tell
I removed the colon as suggested and it worked. I have set the script up to copy five folders from my user directory. All the folders work except the Documents folder. It gets an error that a file is in use. This happens when the Documents folder already exists on the iPod. If it is not there I get promted for my administrator password and then it proceeds fine. I am still working on it so I will post the code tomorrow to see what I am missing.