Find mount point in an applescript???

I’ve got several applescripts written to work with files - we’ll use a simple one as an example: show in finder. The applescript gets a path to a file, which is calculated in a field in Filemaker:

tell application “FileMaker Pro Advanced”
set myFile to cell “cFinderFileName” of current record
end tell
set theFile to POSIX file myFile as alias
tell application “Finder”
activate
open container of (theFile)
select theFile
end tell

I was wondering why my scripts would work one day and not the next. I finally figured it out and here’s the problem, and it’s a dealbreaker:

The files I’m referencing are on a remote share point (Video) on a server, which mounts as a volume on the desktop. The problem is that the volume does not always mount at the same mount point:
One day, it will mount at /Volumes/Video
Another day, it will mount at /Volumes/Video 1
Another computer may mount it at /Volumes/Video 2

Either way, if the mount point changes, the scripts break!!
I know WHY this is happening: sometimes OS X will create a new mount point if a folder with the current volume name already exists in the /Volumes folder. This can happen if the computer crashes and doesn’t get a chance to clean up the /Volumes folder. There’s not much I can do about that, and I’ve seen several ‘duplicate’ folders in the /Volumes folder ie: Video, Video 1, Video 2, Video 3, etc etc., so it could potentially be anything.

I can write the script to mount the volume, (if it’s not already), that’s not a problem. The problem is where it mounts.
What I’d like to do is start off the script by first mounting the volume, then obtaining the current mount point of the volume and passing that through the script. But I can’t figure out how to obtain the volume’s current mount point. That would be the preferred method because it’s scalable to any mount point scenario.

A workaround would be to dismount the volume, delete the errant mount folder (the one that’s causing the mount point to change), then remount the volume (all via applescript or do shell command). This would force the volume to always mount at /Volumes/Video, but IMHO, it’s a messy workaround. Not only am I potentially inturrupting the user by ejecting the volume, but I’m messing with the filesystem in places I shouldn’t be messing.

Any suggestions?

Hi,

first of all, if your computer crashes very often, I would first remove the cause of the crash
or at least clean up all dead mount points at startup.

This way to mount a volume returns the exact path to the mount point


POSIX path of ((mount volume "afp://user:pass@Server.local/myVolume") as alias)

Thanks stefan
The computer doesn’t crash very often - the point is that it’s not unusual for OS X to leave the /Volumes folder a mess. I’ve seen it many, many times for no particular reason - perhaps it was shut down improperly 2 years ago and the remnants of that are still hanging around. The problem is how to deal with that contingency. I’d love to clean up the mount points at startup but that would require executing a startup script for each workstation - not the best solution.

It looks like your script step is exactly what I’m looking for - I’ll give it a try in a few minutes when I can get back to the project. In the meantime, the script I’m trying to run to mount the volume is run when the Filemaker database is opened, and that seems like as good a time as any to clean up the errant alias in the /Volumes folder and remount the volume. Here’s what I came up with in the last half-hour as a workaround and it seems to work: (it’s rudimentary, but…)

tell application "Finder"
	if exists disk "Video" then
		eject disk "Video"
	end if
	delete alias ":Volumes:Video"
	mount volume "afp://192.168.254.20/Video" as user name "username" with password "password"
	make new Finder window to disk "Video"
end tell

(those aren’t the real usernames and passwords…)
back to work!
thanks!

YAY! Thank you! Actually, this is what I was looking for: (which I derived from your script)

set myPath to POSIX path of (("Video") as alias)

It simply gives me the current mount point that I can then use in the scripts. I’ll mount the volume in a previous step (if not already mounted) and then get the mount point.

I don’t know why I couldn’t figure that one out - sometimes when you’ve been thinking too hard about something, the obvious eludes you…

Thank you!