theUpstairsRoom

iTunes, a network share, and Applescript

I've been slowly getting into Applescript lately since I've moved back to Mac for the majority of my work. I recently went through the process of moving the iTunes library file from my PC desktop to my Mac. After all, you can't have a Mac and use iTunes on your PC!

Anyway, I keep all the actual media files on a network share to ease with backup chores and to allow accessing the files with other players etc...  This hasn't posed any problems in the past, but now that I use a Macbook Pro to interact with iTunes, the network share is not always present.  I wrote a small Applescript to check for the existence of the share and then mount it if it's not there before opening iTunes. Since it seems that catching an error from a failed SMB mounting operation is difficult to do in Applescript, I attempt to grab the computer's IP address and only attempt the mount if it contains a value indicating I'm connected to my home network.

Yes, there is probably a better way to do this, and if anyone knows of one, feel free to drop me a line.

The code:

--Avoid undefined errors probably a better way set check_network to "" set check_wireless to "" try set check_network to do shell script ¬ "ipconfig getifaddr en0" on error set check_wireless to do shell script ¬ "ipconfig getifaddr en1" end try if check_network contains "192.168" or ¬ check_wireless contains "192.168" then tell application "Finder" if not (exists disk "music") then open location ¬ "smb://user:pass@server/music" end if repeat until (list disks) contains "music" end repeat launch application "iTunes" tell application "iTunes" activate end tell end tell end if
Powered by Horde Application Framework
Ohloh profile for Michael J. Rubinsky
Follow me

Twitter Updates

    Downloads

    • Command line utility written in PHP for updating IP addresses to an Enom compatible dynamic DNS service.
    • Horde theme based on colors from an Aeronautical VFR chart
    • Horde block for displaying data from servers running phpSystemInfo.

    Tag Cloud

    Previously

    Links

    • An open source web application framework and collection of applications that I'm currently involved with.
    • In the interests of adding a more personal touch, this is my family website, with personal news, photos, and other goodies!