Skip to content

Instantly share code, notes, and snippets.

@bobmurder
Created November 26, 2012 17:43
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 bobmurder/4149586 to your computer and use it in GitHub Desktop.
Save bobmurder/4149586 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# single step iTunes external drive ejection
disk="/dev/disk2"
music_path=/Volumes/media/music
itunes_pid=$(pgrep "^itunes$")
itunes_status=$(lsof -p "$itunes_pid" | grep "$music_path")
# kill iTunes if has an open filehandle to external drive
if [[ -n "$itunes_status" ]]; then
pkill -sighup "$itunes_pid"
fi
diskutil eject "$disk"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment