AppleScript - need help with outputting

Discussion in 'Mac Programming' started by SimonBM, Dec 12, 2011.

  1. macrumors newbie

    #1
    Hello all,

    I'm new to using AppleScript so please forgive me if my code is rubbish:D

    I have the following script which will let me backup to and from a USB to a users home dir, I have tried mobile accounts but the syncing has been giving me some issues. I have now decided to enable local managed accounts and to let users backup a complete copy of their home dir, my AppleScript lest me do this well but I have a slight issue.

    I cannot seem to find a way to output the progress of the backup in AppleScript, the backup works fine but I need to show the users for feedback so the know when the backup is finished.

    Here is the script:

    tell application "Finder"
    if not (exists disk "BACKUP") then
    display dialog "No Backup Disk Detected"
    quit
    end if

    if exists disk "BACKUP" then
    set CurrentUser to do shell script "whomami"
    set question to display dialog "What would you like to sync?" buttons {"From Mac","To Mac","Cancel"} default button 3
    set answer to button of returned question

    if answer is equal to "From Mac" then
    try
    do shell script "rsync -vaE --delete --update '/Users/"& CurrentUser &"/' '/Volumes/BACKUP/Sync/ '"
    end try
    else
    if answer is equal to "To Mac" then
    try
    do shell script "rsync -vaE --delete --update '/Volumes/BACKUP/Sync/' '/Users/"& CurrentUser &"/'"
    end try
    end if


    end if

    end tell

    Hope someone can help!!

    Thanks in advance,

    Si
     
  2. a8ball, Dec 12, 2011
    Last edited: Dec 12, 2011

    macrumors newbie

    #2
    display dialog "Done!" (after your end try?)

    Because you are running rsyn from a shell I dont thin you can update its actual progress.

    Here is a thread with someone trying to solve same issue http://macscripter.net/viewtopic.php?id=30838
     
  3. macrumors 65816

    Partron22

    #3
  4. macrumors newbie

    #4
    Thanks for the info in display a dialog box after the shell scripts end try that works well, now need to make sure a dialog box is open while the transfer is happening. just so the USB isnt unplugged until it says its done.

    is it worth me trying to do the apple script in xcode? colleagues have suggested i learn ObjC and build the app from scratch, but it seems a lot of effort for something so simple and i dont really fancy bloating the program.

    not to mention the syntax of ObjC looks extremely confusing, and wouldnt know where to begin learning.
     
  5. macrumors 65816

    Partron22

    #5
    If you do more than a little casual scripting it is the way to fly. Starting out in AppleScript Objective c requires remarkably little ObjC knowledge, and provides a vastly improved user interface over straight Applescript. The learning curve on Xcode is a little steep, but there's a very nice ebook on ASOC to help you get started:
    http://www.macosxautomation.com/applescript/apps/
     

Share This Page