applescript to copy users home file

Discussion in 'Mac Programming' started by tekboi, Mar 5, 2014.

  1. tekboi macrumors 6502a

    tekboi

    Joined:
    Aug 9, 2006
    Location:
    EasŦcoast
    #1
    I have a script written for personal usage that will duplicate the my home folder to a shared server at work. But I want to make this more portable so that I can share it with co-workers who can run it without having to touch much code.

    There is also the issue it not running more than once because there is already a previous file from running the script once. I get the error saying that "An item with the same name already exists in this location.


    How can I achieve this? Here is the code I currently have:

    Code:
    set vserver to POSIX file "/Volumes/(user)"
    set source to POSIX file "/Users/(homefoldername)
    
    tell application "Finder"
        duplicate source to vserver
    end tell
     
  2. ghellquist macrumors regular

    Joined:
    Aug 21, 2011
    Location:
    Stockholm Sweden
    #2
    rsync

    Check the command rsync ( it runs from terminal ). It does the job even better.
     
  3. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #3
    Yeah, rsync may well be the way to go. It has the advantage of not copying files that already exist on the server. So, for example:

    Code:
    rsync -av ~/ /path/to/folder/on/server
    If you really want it as part of an AppleScript then:

    Code:
    do shell script "rsync -av ~/ /path/to/folder/on/server"
    I suggest you look at the man page for rsync, you'll probably want to check and tweak some of the options.

    Good luck
     

Share This Page