Multiple directory duplicate with timestamp-AppleScript

Discussion in 'Mac Programming' started by Kenshodin, Jun 22, 2016.

  1. Kenshodin macrumors newbie

    Jun 22, 2016
    Hello All!

    I am very new with apple script, and I am having two issues I would love some help with the script below.

    My goal is to copy the two "Folders" from two separate directory locations into one newly created folder on the desktop that is date stamped.


    1. Create new folder called: NewTestFolder(date)
    2. Duplicate Macintosh HD:Users:User: Desktop:TestFolder to NewTestFolder
    3. Duplicate Macintosh HD:Users:User: Desktop:TestFolder2 to NewTestFolder

    End result is "TestFolder" & "TestFolder2" are copied to the newly created "NewTestFolder(date)"

    Here is what I have so far...

    tell application "Finder"
        set p to path to desktop
        make new folder at p with properties {name:"NewTestFolder"}
        duplicatefolder "Macintosh HD:Users:User:Desktop:TestFolder" tofolder "Macintosh HD:Users:apple:Desktop:NewTestFolder"
        duplicatefolder "Macintosh HD:Users:User:Desktop:TestFolder2" tofolder "Macintosh HD:Users:apple:Desktop:NewTestFolder"
    end tell
    Thank you very much for your time!
  2. superscape macrumors 6502a


    Feb 12, 2008
    East Riding of Yorkshire, UK
    You don't mention what your problems are, however, using a little guess work I think something like this should do the job:

    tell application "Finder"
        set p to path to desktop
        --get the date: I use a little shell script to do this because I find AppleScript's
        --native method too fiddly
        set theDate to do shell script "date \"+%Y-%m-%d\""
        --you might want to think about what you want the script to do if the
        --folder already exists
        set theNewFolder to make new folder at p with properties {name:"NewTestFolder (" & theDate & ")"}
        --nb. If the folder already exists then we replace it. Just knock the "with replacing"
        --off the end if you don't want that to happen. If you do that, you should probably think about
        --what to do if the folder alreday exists
        duplicate folder "Macintosh HD:Your:Path:Here:" to theNewFolder with replacing
        duplicate folder "Macintosh HD:Your:Other:Path:Here:" to theNewFolder with replacing
    end tell

Share This Page