Posted on 04-11-2016 09:21 AM
Hi All,
I've been trying to find a "good way" of doing this and am coming up short - does anybody have a nice way of somehow showing progress or status from a terminal command in an osascript-created dialog? Is this even possible? :) I'm using rsync -avhP to get the progress and want to send that output to a dialog window if possible.
We've got a departed user Self Service item that copies the user's home folder to our server and smb share copies are NOT fast - so I'd love to have some sort of progress for my techs running this.
Any cool ideas?
Thanks!
mbezzo
Solved! Go to Solution.
Posted on 04-11-2016 01:31 PM
@mbezzo we are using a Self Service script to backup our departed users as well. We use Cocoa Dialog to show the progress. It is not as clean as looking at the output on the command line but it gives a basic idea of what is happening in the background. This part of the script would require adding Cocoa Dialog to the /Library/Application Support/JAMF/bin/ folder on the client.
Below is not the full script but just the progress bar portion. It assumes you have mapped an SMB drive to /Volumes/whatever/ and created appropriate folders and have a variable for the username.
# create a named pipe
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
# create a background job which takes its input from the named pipe
/Library/Application Support/JAMF/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog progressbar --indeterminate --stoppable stop enabled --title "User Backup Process" --text "Please wait..." < /tmp/hpipe &
# associate file descriptor 3 with that pipe and send a character through the pipe
exec 3<> /tmp/hpipe
echo -n . >&3
# do all of your work here
echo "0 Starting Copy of Desktop" >&3
caffeinate rsync -ahP /Users/$username/Desktop/ /Volumes/whatever/Desktop >&3 2>error.txt
echo "0 Starting Copy of Documents" >&3
caffeinate rsync -ahv --progress /Users/$username/Documents/ /Volumes/whatever/Documents >&3 2>>error.txt
echo "0 Starting Copy of Downloads" >&3
caffeinate rsync -ahv --progress /Users/$username/Downloads/ /Volumes/whatever/Downloads >&3 2>>error.txt
# now turn off the progress bar by closing file descriptor 3
exec 3>&-
# wait for all background jobs to exit
wait
Posted on 04-11-2016 09:40 AM
You want to show some kind of progress In an osascript based dialog? Not really possible. Base Applescript doesn't have any kind of progress bars to speak of. Only 'display dialogs', 'selection/save windows', 'enter password' and such. But there is no "progress bar" window style with Applescript.
Your choices for this could be one of the following:
There are probably a few other options, but those would be the avenues I'd look at for this. FWIW, I've done option 2, Platypus + cocoaDialog a few times myself, even one that uses an rsync backup process, but I'm not using the moving progress bar style, just the indeterminate progress bar. While the -P flag will show progress for rsync, its not done in a way that makes it easy to extract and get into another tool like cocoaDialog to make the bar 'progress' along, so YMMV with any of the above approaches.
Posted on 04-11-2016 09:59 AM
Hello,
Cool. Thanks for the info! I'm hoping for simply just showing the text output of the rsync -P in a window. Is that possible? Like have it poll every 5 seconds or something and show the text output? I don't need a fancy barber pole progress thing - just something to show things are actually happening.
rsync -p outputs like this:
21 files to consider
./
564d2d90-cd47-2ffd-7247-1bc495bd3a01.vmem
2.15G 100% 189.70MB/s 0:00:10 (xfer#1, to-check=19/21)
Can you pass something like that to a dialog or are they unable to actively take text?
If not, I guess I'll have to dive into your options. :)
Thanks!
Posted on 04-11-2016 10:29 AM
I see now. So for that you could look at using Playypus. It has a "log window" style window that's built in which should work well for this. Basically the output from rsync could be piped back into this window and it will keep writing new lines, scrolling as necessary to show what its backing up. In fact, that's basically how the backup application I wrote works. It does use some cocoaDialog stuff but you could skip that part and just use AppleScript to prompt for selecting the home folder to back up and let the built in Platypus UI do the rest.
Posted on 04-11-2016 10:32 AM
Sounds great - will check out Platypus.
Thanks, as always!
Posted on 04-11-2016 10:33 AM
You could do something like:
jamf displayMessage -message "Information "$rsyncinfo""
osascript -e 'display dialog "Information "' $rsyncinfo '"'
Posted on 04-11-2016 01:31 PM
@mbezzo we are using a Self Service script to backup our departed users as well. We use Cocoa Dialog to show the progress. It is not as clean as looking at the output on the command line but it gives a basic idea of what is happening in the background. This part of the script would require adding Cocoa Dialog to the /Library/Application Support/JAMF/bin/ folder on the client.
Below is not the full script but just the progress bar portion. It assumes you have mapped an SMB drive to /Volumes/whatever/ and created appropriate folders and have a variable for the username.
# create a named pipe
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
# create a background job which takes its input from the named pipe
/Library/Application Support/JAMF/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog progressbar --indeterminate --stoppable stop enabled --title "User Backup Process" --text "Please wait..." < /tmp/hpipe &
# associate file descriptor 3 with that pipe and send a character through the pipe
exec 3<> /tmp/hpipe
echo -n . >&3
# do all of your work here
echo "0 Starting Copy of Desktop" >&3
caffeinate rsync -ahP /Users/$username/Desktop/ /Volumes/whatever/Desktop >&3 2>error.txt
echo "0 Starting Copy of Documents" >&3
caffeinate rsync -ahv --progress /Users/$username/Documents/ /Volumes/whatever/Documents >&3 2>>error.txt
echo "0 Starting Copy of Downloads" >&3
caffeinate rsync -ahv --progress /Users/$username/Downloads/ /Volumes/whatever/Downloads >&3 2>>error.txt
# now turn off the progress bar by closing file descriptor 3
exec 3>&-
# wait for all background jobs to exit
wait
Posted on 04-11-2016 03:09 PM
@bkramps Great, thanks for this. Will definitely check it out.
Posted on 04-12-2016 08:26 AM
@bkramps Quick question - when calling CocoaDialog to generate the progress bar, do you get the "can't be opened because it is from an unidentified developer" pop up, or does calling it from a script get around that?
If it does pop up, how do you suppress it?
Thanks!
Posted on 04-12-2016 08:35 AM
@mbezzo Yes, running from the script would not give that prompt. CocoaDialog is different in the sense that you never actually run the app itself, in the traditional sense. Double clicking the app doesn't do anything helpful. It is really just used from the command line.
Posted on 04-12-2016 08:43 AM
Okay perfect, thanks! Working on massaging your code into my existing script now. :)
Posted on 04-12-2016 09:14 AM
@bkramps Beautiful! It's working great. REALLY appreciate the code share!
Posted on 12-28-2018 12:42 PM
@bkramps is there a way to do this with the jamfhelper or other built-in tool? Adding Cocoa dialog to all our machines is my hangup here partly because I haven't found a way to install it easily, and the project itself doesn't seem to be maintained and i'm afraid of it breaking between OS updates etc.