Skip to content

Instantly share code, notes, and snippets.

@myhd
Created September 7, 2012 11:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myhd/3665486 to your computer and use it in GitHub Desktop.
Save myhd/3665486 to your computer and use it in GitHub Desktop.
Script to connect to an AFP server when iTunes is running
#!/bin/sh
# This script will connect to an AFP server when iTunes is running
# 2012-09-07
HOST="hostname" # AFP server, e.g. server.local or 192.168.1.94 or…
USER="your_user_name" # for connection to AFP server
PASS="your_password" # for connection to AFP server
VOLUMENAME="your_volume_name" # name of volume to be mounted, typically username on AFP server.
# No need to configure below ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
while :
do
if [[ $(ps axo pid,command | grep "/Applications/[i]Tunes.app/Contents/MacOS/iTunes ") ]]; then
if [ ! -d "/Volumes/${VOLUMENAME}" ]; then # iTunes runs, Server not mounted
echo "iTunes runs, now mounting ${VOLUMENAME}..."
mkdir "/Volumes/${VOLUMENAME}"
mount_afp afp://${USER}:${PASS}@${HOST}/${VOLUMENAME} "/Volumes/${VOLUMENAME}"
fi
fi
sleep 2
done # start over
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment