2 Replies Latest reply: Jan 18, 2012 9:44 AM by pierrot10
pierrot10 Level 1 Level 1 (0 points)

Dear All,


I working hard to make my firts backup script with Apple script.


I have a rsync command which copy the file from a place toenother one.


While the rsync process is running, I would like to have the % of the process in order to let the user to know where is the state.

Is there a way to do it and how?


I can use somethink else than rsync, but be aware that I ahev to use smb protocole because my data are synchronized from Apple to Linux or Windows server.


Any suggestion?




  • Camelot Level 8 Level 8 (46,480 points)

    There's no direct way to get the progress of your rsync command - once AppleScript calls the do shell script command it has no visibility into what that command is doing until it's finished.


    There is one workaroud, but it takes some effort. You can execute the shell command in the background - this passes control back to your AppleScript while the shell command is still running. In addition, you can redirect the output of the shell command to a file and your AppleScript can read that file to determine the progress of the command. It's not trivial to do, but it's about the only option you have.


    -- run the command

    set thePID to do shell script "/path/to/lengthy/process &> /var/tmp/my.out & echo $!"

    -- grab its ID

    set processIsRunning to true

    -- repeat while it's running

    repeat until processIsRunning is false

              tell application "System Events"


      -- if this works, the process is still running

                                  do shell script "ps -p " & thePID

      -- so grab the last line of the output file

                                  set progress to last paragraph of (read POSIX file "/private/var/tmp/my.out")

                        on error

      -- if we get here the process isn't running, so clean up

                                  set processIsRunning to false

                                  do shell script "rm /var/tmp/my.out"

                        end try

              end tell

      -- show the output

      display dialog progress

    end repeat

  • pierrot10 Level 1 Level 1 (0 points)

    Thank for this solution,

    I will try it and see how it work (and see if I get it )