Search code examples
copyapplescriptrsync

AppleScript copy/duplicate only newer files


I have created an AppleScript that mounts a network smb share, creates folders if they don't exist then copy files to these new folders.

I am using:

duplicate items of folder <source> to <destination> with replacing

This will copy over and replace all the files. Is there a way to only duplicate newer files?

Should I be using rsync rather than duplicate?


Solution

  • I'd definitely use rsync, with possibly the -a flag (archive option, it will work recursively along with other mirroring options, check the man page for better options for you)

    rsync -a (source) (destination)
    

    Call from applescript using the do shell script command, making sure you pass in posix paths.

    eg,

    set source_path to quoted form of POSIX path to source
    set dest_path to quoted form of POSIX path to destination
    do shell script "rsync -a " & source_path & " " & dest_path