Mounting AFP with AppleScript putting a hyphen in the mount name?

I have a script that mounts a couple AFP volumes, like so:

tell application "Finder"
try
mount volume "afp://username:password@192.168.0.10/live"
end try
end tell

The problem is, occasionally (but not always) this will create an empty "live" folder in /Volumes/, along with a proper mount under the name "live-1". Does anyone know how I can prevent this from happening?

Posted on Jan 25, 2011 10:03 AM

Reply
9 replies

Jan 25, 2011 10:43 AM in response to ashground

The number is appended if you try to mount a volume that has the same name as an existing volume - for example, if you mount the volume 'live' and you already have a mounted volume called 'live' (even from another disk, server, disk image, etc.) then the new one will be called 'live-1' to differentiate it.

As for solution? Well, check there isn't already a 'live' volume mounted before you try to mount the new one...

tell application "Finder"
if not (disk "live" exists) then
mount volume "afp://user:pass@server/live"
end if
end tell

Jan 27, 2011 6:34 PM in response to ashground

Yeah, same here. I've no idea how that's happening there. I did notice though that mount volume is doing some odd stuff. If used when the volume is already mounted, it'll unmount the volume - even if it's in the middle of being used for file copying.

Sorry, no idea what's happening there. Best idea I can think of is to try to dynamically determine the name of the volume - checking for the regular name and the same name with the suffix "-1". It's messy, but might be a workaround.

Alternatively you could use the terminal command mount_afp to mount the volume at a specific location, but then of course you get in to the messy business of having to add and remove folders in /volumes to act as the mount point.

Message was edited by: The Preacher

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mounting AFP with AppleScript putting a hyphen in the mount name?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.