Retrieving Mounted AFP Volumes URL

Hello,

I'm building an apple script app to generate a url for any file selected in finder on network volumes.  I would like to put it in the form of smb://server/share/path to file or afp://server/share/path.  However, I'm unable to find how to access the address of afp mounts.  I can get the smb mounts by using the mount command through do shell script, but the afp mounts in the mount output, show up with a weird address...[i]afp_4meaic000eRk0000oM0000VU-1.2e000013 on /Volumes/testAFP (afpfs, nodev, nosuid, mounted by elevate)[/i]

If I use System Events I can find the name of the server I’m accessing by:

tell application "Finder"
	set mySelection to selection as alias
	set myDisk to URL of disk of mySelection
end tell

tell application "System Events"
	set myServer to (properties of disk "/Volumes/testAFP")
end tell

But this will not get the share name the mount is accessing. You could use the name of the mounted drive, but if you mount the drive manually through the command line with an alternate name, or have multiple mounts with the same name, this is not possible. Any ideas how to get this address? If I go to the computer in finder, and get info, it shows up perfectly in the Server information displayed. I could use applescript to get info for the selected drive in finder, and read that text from the dialog, but the app needs to be faster than the time it would take to do all of that. I’m open to any suggestions you have.

Thanks,
Brennan

Hi,

System Events’ items have volume and server properties, the server information is only available if the item is located on a shared volume

tell application "Finder"
	set theFile to item 1 of (get selection) as text
end tell

tell application "System Events"
	set volumeName to volume of file theFile
	try
		set serverName to server of file theFile
	on error
		display dialog "file " & theFile & " is not on a shared volume"
	end try
end tell

By the way: AppleScript works only with HFS paths (no slashes)

tell application "System Events"
   set myServer to properties of disk "testAFP"
end tell

I know this is an old post, but it is relevant to me. The problem is that Stefan’s script errors even though the file I choose is on a shared volume. Does anyone know why?

The thing I would like to do is to find out what afp address a file uses. This can be found by choosing a file in finder and getting information. The line I want is the “Server:” entry. Ultimately what I would like to do is to use that afp address to create email links in Mail.

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

Sorry, my fault, the server information can be retrieved from the disk object.
The afp path can be composed


tell application "Finder"
	set theFile to item 1 of (get selection) as text
end tell

tell application "System Events"
	set volumeName to volume of file theFile
	set serverName to server of disk volumeName
	if format of disk volumeName is AppleShare format and serverName is not missing value then
		set filePath to POSIX path of file theFile
		set afpPath to "afp://" & serverName & ".local/" & text 10 thru -1 of filePath
		display dialog afpPath
	else
		display dialog "file " & theFile & " is not on a shared volume"
	end if
end tell


Thanks for your quick response Stefan. That has certainly helped me on the way.

However, it only partly worked. It collected the server name, but adding the “.local” part caused the link to not work. I can, of course, get around this for a situation I am aware of, but is there a way of ascertaining whether or not “.local” is needed. An error section perhaps “ something like trying to make an alias to the afp link with “.local” in it and if an error then reconstruct the link without it?

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

the .local domain indicates the local network

you can make an alias only from file system scheme URLs (file://.) not from other scheme URLs like afp://, smb:// or http://

Hi Stefan

Okay, I was accessing the server via VPN and local did not work. Trying your script worked with local when accessing the server within the building, but it also worked without the local bit.

Do you have any idea if this behaviour would be the same for all mac networks?

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)