Ami and Ken

Q: How to show rsync progress using automator?

I am using an Automator script to rsync two folders.

The problems is I don't know how much time is remaining when I sync the (very large) folders.

I know I can use --progress in Terminal if I run everything through Terminal. But I like this script because it asks me which folders / volumes to sync ... it dumbs it down for me.

 

Does anyone know a solution to make --progress data visible if I keep this in Automator?

 

Thanks.

-Ken

Posted on Jan 29, 2016 1:26 PM

Close

Q: How to show rsync progress using automator?

  • All replies
  • Helpful answers

  • by Tony T1,

    Tony T1 Tony T1 Jan 29, 2016 2:09 PM in response to Ami and Ken
    Level 6 (9,249 points)
    Mac OS X
    Jan 29, 2016 2:09 PM in response to Ami and Ken

    If you use the Run Applescript Action (instead of the Run Shell Script Action) with a "do script" a Terminal Window will be visible (you will need to close the Terminal Window after rsync completes)

     

    Pass the command to the Applescript Action which will be the input variable:

     

    Screen Shot 2016-01-29 at 5.07.59 PM.png

  • by Camelot,

    Camelot Camelot Jan 29, 2016 2:01 PM in response to Ami and Ken
    Level 8 (47,285 points)
    Mac OS X
    Jan 29, 2016 2:01 PM in response to Ami and Ken

    The standard/typical solution to this involves redirecting the output of the rsync command to a file, then have a separate process/thread watch the log file and parse the data.

     

    By default, when you invoke a shell command, the rest of the AppleScript/Automator actions wait until that process finishes, so this allows the process to continue in the background while you work on displaying the data to the user.

     

    Automator isn't my first choice, though - it's just too hard to get loops and branches working.


    In AppleScript, here's a crude example that will show a theoretical progress counter via the Notification Manager

     

    repeat with i from 1 to 10

      display notification ((i * 10) as text) & "%" with title "My Progress"

      delay 1

    end repeat

     

    The trick here is deciphering rsync's log to understand how it's progressing.

  • by VikingOSX,

    VikingOSX VikingOSX Jan 29, 2016 2:40 PM in response to Ami and Ken
    Level 7 (20,819 points)
    Mac OS X
    Jan 29, 2016 2:40 PM in response to Ami and Ken

    The following assumes that you have downloaded Rsync Wrapper from this location, and it is in your search path. Credits to StefanK at MacScripter.

     

    The script will provide a running progress meter with percentage in a window, as rync runs. When rsync has finished, a pop-up display of the copy statistics will be presented. I used the same AppleScript as StefanK posted in the above link. Rsync Wrapper works fine when tested on El Capitan 10.11.3. Hope it helps you.

     

    After I unzipped Rsync Wrapper in my Downloads folder, I soft-linked it into my ~/bin directory by the same name. ~/bin is in my search path, and I could just use it in the AppleScript without path issues.

     

    The underlying ideas for the AppleScript/Objective-C Rsync Wrapper came from this post.

     

    Here is the AppleScript that I used to copy the contents of my Picture folder to another empty folder named POut.

     

    set theSource to POSIX path of ((path to home folder) as text) & "Pictures:"

    set theDest to POSIX path of ((path to home folder) as text) & "POut:"

     

    tell application "Rsync Wrapper"

         activate

         set {exit code:exitCode, error message:errorMessage, items transferred:filesCopied, statistics:stats} to rsync from source theSource to destination theDest arguments {"-au", "--exclude=.DS_Store"}

     

    end tell

    if exitCode is not 0 then

         display dialog errorMessage

    else

        display dialog stats

    end if


    return

  • by VikingOSX,

    VikingOSX VikingOSX Jan 29, 2016 3:23 PM in response to VikingOSX
    Level 7 (20,819 points)
    Mac OS X
    Jan 29, 2016 3:23 PM in response to VikingOSX

    As an addendum, one can copy the Rsync Wrapper package into /Applications too. It has its own scripting dictionary, and will show up in the Script Editor's dictionary list of applications.