Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

how to copy folder with applescript?

hey there!

i have a question about AppleScript. How do I COPY a folder in a nother folder like:

move folder (user:name:documents) to folder (user:name:desctop).


But I wannt to COPY it.

Anyone knows something?


Thanks 😉

AppleScript-OTHER, Mac OS X (10.7.2)

Posted on Jan 23, 2012 9:01 AM

Reply
Question marked as Best reply

Posted on Jan 23, 2012 9:30 AM

The Finder is usually the application to target for file stuff, so the first step would be to look at its scripting dictionary to see what terminology it has, for example:


tellapplication"Finder"


duplicatesomeFileReferencetosomeFolderReference

endtell

7 replies

Jan 23, 2012 9:58 AM in response to red_menace

ok thank you but now i have a problem when i write:


set x to "Desktop" of folder "marcolilli" of folder "Users" of startup disk

set y to "H12" of folder "Documents" of folder "marcolilli" of folder "Users" of startup disk


tell app "finder"

duplicate y to x

end


you know why? i think there's a problem with the history ( "desctop" of folder....) how do i spell that right?

could you write me a sample with my folders?

Jan 23, 2012 10:26 AM in response to marcco

One thing to remember is that AppleScript itself doesn't know that much about files and folders, so if you are going to be using Finder references you need to put them inside the Finder tell statement. To use file and folder references outside of the Finder tell statement, you will need to use aliases (or the keywords file or folder when using text strings), for example


setxto (path todesktop folder)

set y to (((path to documents folder) as text) & "H12") as alias

Jan 23, 2012 11:10 AM in response to red_menace

ok, thank you sosososososossososo much. but now (my last thing) i have always the problem that when i would make something like that:


set x to ((((path to library folder) as text) & "Application Support") & "minecraft") & "saves)

set y to (((path to documents folder) as text) & "minecraft") as alias

tell application "Finder"


duplicateytox

end tell


ist does'nt work... could you write a right version of that ?(i want that x ist the folder "saves" in the folder "minecraft" in the folder "application support" in the folder "library".

and that y ist the folder "minecraft" in the folder "documents")


pls pls help and thanks for the help till now

Jan 23, 2012 11:58 AM in response to marcco

Your paths would be:


setxto (((path toapplication support fromuser domain) astext) & "minecraft:saves:") asalias

set y to (((path to documents folder) as text) & "minecraft:") as alias

What exactly are you wanting to do? The script doesn't look quite right to me, since you will be copying the entire "minecraft" folder in your Documents folder into the "minecraft:saves" folder in your user's Application Support folder. If you are trying to backup your saves, I would think that the copy direction should be going the other way. Even if the direction of the copy is correct, you will probably run into an error at some point if the folder already exists - the duplicate command has a replacing option that you can set to replace the existing item (be careful to check the script on test data so that you don't overwrite stuff you want to save), for example:


tellapplication"Finder"


duplicateytoxwithreplacing

endtell

Feb 6, 2012 1:15 PM in response to red_menace

riddle me this,


what if I didn't want it to delete the target file when I say with replacing?


for example I could have file 1 and file 2 in my destination folder, and file 3 in my source folder - but if I use with replacing, it deletes the folder and recreates it with only file 3 thus losing file 1 and file 2.


essentially what I am after is a merge. I know I could use cp shell command, but that way I will not have a progress bar.


thank you in advance.

Feb 6, 2012 4:48 PM in response to matthardwick

The with replacing parameter just replaces the file if there is already one at the destination that has the same name, otherwise there will be an error (since the file already exists). Another way would be to change the name in some way (for example using a suffix) to make a name that is unique at the destination.


In the future you should start a new topic with details about your particular issue, since your response doesn't apply to the original poster's question.

how to copy folder with applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.