Skip to content

Instantly share code, notes, and snippets.

@marckohlbrugge
Last active January 25, 2017 22:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marckohlbrugge/e0f16143fa0a3527c2fd06f9663337fa to your computer and use it in GitHub Desktop.
Save marckohlbrugge/e0f16143fa0a3527c2fd06f9663337fa to your computer and use it in GitHub Desktop.
#/bin/bash
# README:
# - Make sure to make the script executable using chmod
# - chmod +x file_name.sh
# (chmod stands for change mode)
# (x stands for executable)
# This script builds upon the work of 'mrzarquon' found here:
# http://ask.metafilter.com/142872/Help-me-archive-a-roomful-of-old-Mac-data
# Find the disk mounted by optical media
# You might need to change /dev/disk2 to something else
# Run `df` to see the name of your disk
opticalMedia=`df | grep /dev/disk2 | cut -d '/' -f 5`
# Check if the disk is available
if [ -z "$opticalMedia" ]; then
echo "No disc inserted."
# Yes, a disk is available
else
# Double check it's indeed available
if [ -d "/Volumes/$opticalMedia" ]; then
# Uncomment these lines if you want to force unique DVD names
# if [ -d "/Volumes/MyBook 1TB/DVDs/$opticalMedia" ]; then
# is there a name conflict? fix it.
# timestamp = `date +"%Y%m%d_%H%M"`
# targetname="$opticalMedia-$timestamp"
# else
#no conflict. yay.
targetname="$opticalMedia"
# fi
# Try to rsync the drive to our destination folder
if rsync -aEpv "/Volumes/$opticalMedia/" "/Volumes/MyBook 1TB/DVDs/$targetname"; then
echo "Successfully rsynced the drive."
osascript -e "display notification \"Successfully imported the drive with no errors.\" with title \"Successfully imported $opticalMedia\" sound name \"Glass\""
diskutil eject /dev/disk2
else
# Whoops! Something went wrong.
errorMessage=`$?`
osascript -e "display notification \"$errorMessage\" with title \"Error importing $opticalMedia\" sound name \"Funk\""
diskutil eject /dev/disk2
exit 1
fi
else
echo "whoops. nothing there, drive misidentified, or some other bug"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment