I was wondering if someone could help me with this question. I’ve created an Applescript that does a lot of stuff, one of them is doing a rsync shell script. What I would like to do is to have a progress bar that can show me the progress of the rsync, I know that this couldn’t be done in Applescript since I’m running a shell script but is there a way I can call a Cocoa display or something else so It can do the trick?
here’s the part of the script I would like to have a progress bar for
do shell script "/usr/bin/rsync -vautE " & quoted form of text 1 thru -2 of sourceFolder & space & quoted form of targetFolder
Otherwise you could write an Cocoa AppleScript application build it all from scratch. This post might be helpful for getting the output of the rsync task: http://macscripter.net/viewtopic.php?id=42606
Thanks a lot for the reply. I’m a bit new in ASObjC so sorry for asking but do I need to have the ASObjC Explorer for Mavericks to run Sahne’s Runner or could it work with only Apple script?
If you are looking to write the AppleScriptObjC-based libraries yourself then you could use the Explorer editor. And while I have only used a trial of Explorer in a few instances, it seems like a great tool overall.
But you don’t need Explorer to use the Runner application and can call it from a pure AppleScript application.
So I did try the Shane’s runner progress bar and it seems pretty good. the only weird thing is that this progress bar seem to run after the rsync instead of during. I guess this is due to the fact that the update occurs after the Rsync. Do you know of a way that the progress bar can run during the Rsync (so we can monitor the rsync progress)?
Here’s the script I’ve used
set sourceFolder to POSIX path of (choose folder with prompt "Choose a folder to copy:")
set targetFolder to POSIX path of (choose folder with prompt "And where do you want it to go?")
set {TID, text item delimiters} to {text item delimiters, "/"}
set sourceFolderName to text item -2 of sourceFolder
set text item delimiters to TID
property defaultGroups : {"Family", "Friends"}
property defaultLabels : {}
tell application "ASObjC Runner"
-- set up dialog and show it
reset progress
set properties of progress window to {button title:"Cancel", button visible:true, message:"Rsync Progress", detail:"More text can go here", indeterminate:false, max value:100, current value:0}
activate
show progress
end tell
delay 0.5
repeat with i from 1 to 100
do shell script "/usr/bin/rsync -vautE " & quoted form of text 1 thru -2 of sourceFolder & space & quoted form of targetFolder
delay 1 -- for effect
-- update dialog
tell application "ASObjC Runner"
activate
set properties of progress window to {detail:"This is number " & i, current value:i}
if button was pressed of progress window then
exit repeat
end if
end tell
end repeat
-- hide dialog
tell application "ASObjC Runner" to hide progress
The variable newString contains the output you can see when you run the script in Terminal.app.
You have to parse the output and populate / update the progress bar
thanks a lot for the reply and sorry for the delay on my feedback as I was out of the country for the past 3 weeks. I did try the Cocoa wrapper but I have 2 little questions.
Right now, when trying the example code you provided, I can see that it’s displaying a progress bar (yeah :-)) but it’s seems to be statics and there’s also and empty dialog box with only an ‘‘ok’’ and ‘‘Cancell’’ button. Is it normal?
Also, should I place this code somewhere in particular? Right now I’ve tested right after my ''do shell script "/usr/bin/rsync -vautE " & quoted form of text 1 thru -2 of sourceFolder & space & quoted form of targetFolder<< line, but it does’t seems to work as the progress bar is waiting for the rsync to be finished before to start.
the Cocoa wrapper is a standalone solution, there is no shell script needed
You have to change this line
set {exit code:exitCode, error message:errorMessage, items transferred:filesCopied, statistics:stats} to rsync from source "/path/to/source" to destination "/path/to/destination" arguments {"-au", "--exclude=.DS_Store"}
replace “/path/to/source” with the source path
replace “/path/to/destination” with the destination path
replace {“-au”, “–exclude=.DS_Store”} with just {“-au”}, omit the v, t and E switches or keep the expression if you want to exclude the invisible .DS_Store files
for example
set sourceFolder to (choose folder with prompt "Choose a folder to copy:")
set targetFolder to (choose folder with prompt "And where do you want it to go?")
tell application "Rsync Wrapper"
activate
set {exit code:exitCode, error message:errorMessage, items transferred:filesCopied, statistics:stats} to rsync from source sourceFolder to destination targetFolder arguments {"-au", "--exclude=.DS_Store"}
end tell
if exitCode is not 0 then
display dialog errorMessage
else
display dialog stats
end if
I did try to run the Rsync Wrapper on some of my other CPU and for some reason didm’t seem able to do so.
The first I tried came back with an error saying ‘‘couldn’t find Rsync Wrapper application’’. I thought this was due to the fact that this station was running under 10.8.4, so I tried on another station running under 10.9.3 and still wasn’t able to run it. This time, my script came up with a ‘‘Error of type -10810’’
I was wondering if it was normal the the RSYNC seems to slow down the transfer? I did some tests with a 16 gig folder and when it took me around 5 minutes to copy when using the finder (just drag and drop) It took almost 7 minutes to transfer it using the RSYNC command.
That was my feeling too. Do you know if this delay is exponential (the larger the folder the longer the delay)?
Also, do you have any idea why I can’t seem to be able to use the Rsync Wrapper on other station (one not finding the Rsync wrapper and the other one giving a -10810 error’'? Do I need to install something else in order for the Rsnc to work?
so I did a couple of tests and realize that to get rid of the -10810 error, I have to go back to my script and add “.app” to the line “tell application “Rsync Wrapper”” so it becomes “tell application “Rsync Wrapper.app””. Though when I compile it the .app seem to disappear, I no longer have the -10810 error. But the Rsync doesn’t seem to work, as soon as it launch, I have an empty dialog window with only two button ok" and “cancelled”.
I also realize that the station which seem to work fine run under Applescript editor 2.6.1, while the others are running under Applescript editor 2.5.1
Is it possible that the RsyncWrapper.app only work under 2.6.1? And if so, does that mean that we need to run OS Maverick? (As I don’t think we can update Applescript Editor by it’s own)
it’s seems to work better than the prior one (doesn’t have the -10810 error anymore) But I still have this strange dialog box when running script. No message, just the ‘‘ok’’ and '‘cancel’ button. If I hit ‘‘ok’’ all it seems to do is skip the rsync command so th next command (checking the mhl) is failing (since the rsync never occurred). If I hit ‘‘cancel’’ then it only cancel my script, the progress bar stays at ‘‘preparing’’ for ever and I have to kill it using the Activity monitor.