I outsourced the storage for my "iTunes Media", "iTunes Music" and "Mobile Applications" using symlinks onto a network drive.

I didn't outsource the complete media library because of performance reasons with iTunes.

It would be nice to connect to my network drive when I launch iTunes as it fails less than gracefully when the network storage isn't already mounted.

Is there a way to mount a network drive prior to a particular application launching?

  • What kind of server is it? AFP, SMB...?
    – myhd
    Sep 5, 2012 at 7:27
  • its a AFP Protocol
    – choise
    Sep 5, 2012 at 12:09
  • if you feel like on load mounting isn't getting you where you wish to be, you can definitely do mount on start up. you simply mount the drive, open user preferences in settings, drag and drop the server connection to the list of applications to start on boot, then select it's check box if not selected. Oct 3, 2012 at 12:54

4 Answers 4


Using Automator and the excellent SleepWatcher utility, I have a setup that automatically connects to my network drive when the computer starts, then automatically reconnects when the computer wakes from sleep.

I've written a tutorial in a blog post.

An update in response to CajunLuke's question:

The Automator app connects to the network drive and incorporates a 10 second delay to ensure the network connection is ready.

SleepWatcher runs as a daemon, and allows you to schedule the execution of scripts when your computer goes to sleep or wakes from sleep. In this case you configure it to run a shell script when the computer wakes that calls the aforementioned Automator app.

  • Can you post the gist of your blog post here? We really prefer to have more content in an answer than just a link (generally due to link rot).
    – Cajunluke
    Oct 4, 2012 at 23:27

And easy solution would be to automatically have your network shares mounted for you when you log in. A program like Network Drive Launcher would aid in automatically scripting and connecting to networked shares when you log in.

Alternatively you could write an Apple Script that would replace clicking on the iTunes icon to start iTunes, not ideal since you would have to click the script first.

  1. Open the AppleScript Editor application.
  2. Type in the following


--open the network location first
tell application "Finder"
    open location "smb://... OR afp://..."
end tell

--wait 10 seconds adjust this time to meet your needs
delay 10

--open iTunes
tell application "iTunes"
end tell
  1. Save the script File > Save

  2. Name it what you like but be sure to set the file format to "Application" on the "File Format:" dropdown.

  3. Run the script, you can treat it like any other Application.

Lastly, it looks like it may possible to write an Apple Script that does exactly what you want, here is a link to something that may be able to work with some modification. I could not get it to work on Lion, some syntax issues need to be resolved. Run a script whenever an application opens

What you need is an applescript that stays open all the time and performs its tasks periodically. So here's an example applescript for you. Save it as an application and check the "stay open" box to make it stay open after you launch it. The way a stay-open script works is there's 2 main handlers, the "on run" and the "on idle". "on run" runs once at application launch. "on idle" runs every so often. You set how often it runs by returning a number of seconds at the end of the handler. So here's the example... it sets up the application parameters in the "on run" handler and then in "on idle" it can check those parameters. Right now this script just displays the results but you can make it do whatever you want at this point. global applicationsToWatch, idleTime ...

  • 1
    thanks for your detailed answer. i see some problems here: i use the option to mount my network drives on startup (simply add them under settings in the user section in launch objects) but i never turn off my computer (mb air). when i go outside i simply close it, coming back with no network drives. the second option looks better but it doesn't work if itunes launches by itself (device connected, remote). probably i need to code a background-helper thats waiting for itunes to launch? dont want that :D i'll try to get this "Run a script whenever an application opens" running.
    – choise
    Jun 20, 2012 at 15:55
  • You might want to look into this for running scripts when your Mac wakes from sleep apple.stackexchange.com/questions/27036/…
    – MrDaniel
    Jun 20, 2012 at 16:01
  • Just a friendly reminder for people to up vote useful answers (and down vote / comment on ones that need help). The site does better when voting recognizes nice contributions like this one....
    – bmike
    Jun 27, 2012 at 18:05

I made a script that connects to a network drive when iTunes is running. You can download it from this gist page (look for the "raw" download link).


HOST="hostname" # AFP server, e.g. server.local or 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.

while :
    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}"
sleep 2
done # start over

Basically, it runs in an infinite loop and checks every two seconds if iTunes.app is running. If so, it checks whether your AFP volume is mounted already, and does so if not.

You’ll have to configure the script before running it for the first time, see the variables on top of the script. VOLUMENAME is the name from the normal AFP connection dialog (ssd in this case):

Connection Dialog

To check if the thing works in principle: Let’s say the script is on the Desktop, in Terminal type cd ~/Desktop/, then ./mount_afp_when_itunes_running.sh.

In case of Permission denied, set the file permissions so that you can run the script with chmod 755 mount_afp_when_itunes_running.sh, then try again.

Finally, if everything works, you could then launch this script automatically via a Launch Agent.


This may be a bit off topic, but there’s no need to symlink the iTunes directories! To select any iTunes library residing anywhere on any disk, just hold immediately after launching iTunes.

enter image description here

  • 2
    the reason for a symlink is another one. if i use symlinking instead of choosing my itunes library the way you discribed, all metadata and thumbnails will be stored on my machine instead of a network drive which speeds up itunes INCREDIBLY.
    – choise
    Aug 8, 2012 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .