Skip to content

Instantly share code, notes, and snippets.

@128keaton
Created November 18, 2016 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 128keaton/2da6cc58791eea389abb0b6ea65a1b23 to your computer and use it in GitHub Desktop.
Save 128keaton/2da6cc58791eea389abb0b6ea65a1b23 to your computer and use it in GitHub Desktop.
#!/bin/sh
POPUP=`dirname "$0"`/cocoaDialog.app/Contents/MacOS/cocoaDialog
# create a named pipe
rm -f /tmp/hpipe
mkfifo /tmp/hpipe
# create a background job which takes its input from the named pipe
$POPUP progressbar \
--float \
--title "Zeroing Disk" \
< /tmp/hpipe &
# associate file descriptor 3 with that pipe and send a character through the pipe
exec 3<> /tmp/hpipe
echo -n . >&3
diskutil unmountDisk /dev/disk0
DISKSIZEBYTES=$( diskutil info /dev/disk0 | grep "Total Size" | sed 's/.*(\([0-9]*\) Bytes.*/\1/g' )
DISKSIZE="$(expr $DISKSIZEBYTES / 1024 / 1024 / 1024)G"
echo "Disk size: $DISKSIZE"
# do all of your work here
(`dirname "$0"`/pv -n -s $DISKSIZE < /dev/zero > /dev/rdisk0) 2>&3
# now turn off the progress bar by closing file descriptor 3
exec 3>&-
# wait for all background jobs to exit
wait
rm -f /tmp/hpipe
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment