PDA

View Full Version : Checking for remote volume before launching iTunes




LoChrome
May 5, 2012, 03:47 PM
I keep my music stored on an AirPort volume (I have an Air and too much music for the HD). I'm trying to write an AppleScript to check if my volume is mountedóand if not, mount itóbefore launching iTunes. Because the volume is a partition on the hard drive, I can't figure out how to reference it directly.

This works okay, but it's crude: it requires I pick the Music partition/volume from a list before mounting it, and if it's already mounted, mount a disk I don't want to mount.

mount volume "afp://MyVolume._afpovertcp._tcp.local"
launch application "iTunes"

(The full Music drive address is "afp://MyVolume._afpovertcp._tcp.local/Music Storage")

The ideal solution would check to see if I'm connected to my Wi-Fi network, mount the disk, then mount iTunes, but I'm really at a loss to do that. Any help to make this work better would be appreciated. I could do this as an AppleScript, Terminal script or Automator app.

Thanks! :apple:



kryten2
May 5, 2012, 05:21 PM
tell application "Finder"
if (exists disk "Music Storage") then
launch application "iTunes"
else
try
mount volume "afp://MyVolume._afpovertcp._tcp.local/Music Storage"
repeat until disk "Music Storage" exists
end repeat
on error theErrorText number theErrorNumber
display dialog "An error occured. The following error number " & theErrorNumber & " was encountered: " & theErrorText buttons {"OK"} default button 1
end try
launch application "iTunes"
end if
end tell


To return a list of the currently mounted volumes :

tell application "System Events" to get the name of every disk
-- → list of text : a list of the currently mounted volumes.

LoChrome
May 5, 2012, 09:48 PM
Oddly, when using my original AppleScript app, my volume properly mounts. When I tried yours, which has the identical mount volume language, I get a "Finder got an error: Network file permission error."

When I was first playing with AppleScript Editor trying to get something to work, I kept getting this same problem. I'm completely baffled as to why the same bit of code executes differently in the different contexts.

Thanks for the more graceful code. I would be an improvement on my solution if it weren't for the baffling permissions bug. (My regular user environment isn't my admin profile, so that may be related to the problem.)

jahala
May 5, 2012, 10:27 PM
I also have my media on an airport drive. About half the time, the computer will automatically mount the drive if I try to access it through iTunes. Sometimes it does not. I don't know why.

kryten2
May 6, 2012, 08:48 AM
What userame and password are you using? How did you configure your AirPort in relation to sharing a drive? The first time you connected did you save anything in Keychain Access? Try this :

mount volume "afp://user:pass@MyVolume._afpovertcp._tcp.local/Music Storage"
or
mount volume "afp://MyVolume._afpovertcp._tcp.local/Music Storage" as user name "user" with password "pass"