Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This only really works if rsyncing entire folders. Single files do work, however it will just appear to stand still (no progress). Also, change the path to cocoaDialog accordingly.
# cocoaDialog Rsync Progress
# Rsync files using the cocoaDialog progress bar. Example usage:
# $ rsync -avr --progress ~/source ~/destination | ./
# Copyright (C) 2014 Mark Carver
# Adapted from Kevin Hendricks example code
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
# Create a named pipe.
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
# Create a background job which takes its input from the named pipe.
~/Applications/ progressbar --float --resize --minimize --title "Syncing Files" --text "Syncing..." --icon sync < /tmp/hpipe &
# Associate file descriptor 3 with that pipe.
exec 3<> /tmp/hpipe;
# Initialize the current percentage.
# Read stdin, line by line.
while read line; do
# Output rsync output as normal (for logging purposes).
echo ${line};
# Parse the rsync output so it can be sent to the progress bar.
line=$(echo ${line} | awk '{
if (index($0, "to-chk=") > 0) {
split($0, pieces, "to-chk=")
split(pieces[2], term, ")");
split(term[1], division, "/");
print (1-(division[1]/division[2]))*100
else if (index($0, "ir-chk=") > 0) {
split($0, pieces, "ir-chk=")
split(pieces[2], term, ")");
split(term[1], division, "/");
print (1-(division[1]/division[2]))*100
else {
print "0 "$0;
# Parse the percentage number.
percent=$(echo ${line} | sed -E 's/^([0-9\.]) [^\/]*\/(.*)/\1/');
# Only increase the percentage if not "0". This allows the filenames to be updated.
if [[ "${percent}" != "0" ]]; then
# Parse the filename being synced.
filename=$(echo ${line} | sed -E 's/^([0-9\.]) [^\/]*\/(.*)/\2/');
# When there is no filename the percentage is parsed instead, reset it.
if [[ "${filename}" == "${currentPercent}" ]]; then
# Output the current percentage and filename to the progress bar file descriptor 3.
echo "${currentPercent} ${filename}" >&3;
done < /dev/stdin;
# Turn off the progress bar file descriptor 3.
exec 3>&-;
# Wait for all background jobs to exit.
# Remove the named pipe.
rm -f /tmp/hpipe
# Exit successfully.
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.