Determining Server

Hi All,

I have a problem that I’m trying to work around and I just can’t seem to find anything on it.

Where I work we have several servers with several share points each and I’m working on a small script that allows a user to drop their file on the applescript app and it gives back the file path to the file. The only problem is when I get back the file path it reads as a POSIX path “/Volumes/Share/Folder/File.app” I would love for it to read “Server/Share/Folder/File.app” so we could share it with other employees who need to see these files but don’t necessarily know which server it lives in. Make sense?

Here’s the script:

on run
	set theButton to (display dialog "Please choose from buttons below for path needed:" buttons {"Cancel", "Folder", "File"} giving up after 60)'s button returned
	
	if theButton is "File" then
		set dest to (POSIX path of (choose file) as string)
	else if theButton is "Folder" then
		set dest to (POSIX path of (choose folder) as string)
	end if
	-------
	set the clipboard to dest
	-------
	display dialog dest & " has been saved to Clipboard" buttons "OK" default button 1 with icon 1 giving up after 60
end run
----------
on open theItem
	if (count theItem) > 1 then return display dialog "Can only drop 1 item at a time on droplet" buttons "OK" default button 1 giving up after 60
	-------
	set dest to (POSIX path of theItem as string)
	-------
	set the clipboard to dest
	-------
	display dialog dest & " has been saved to Clipboard" buttons "OK" default button 1 with icon 1 giving up after 60
end open

I know the script is going to have edit the file path variable I have but I’m having a slow moment and can’t figure out how to read what server the share is on :slight_smile:

Thanks in advance. This forum has been a great help!

AppleScript: 2.1.2
Browser: Safari 534.57.2
Operating System: Mac OS X (10.6)

Hi,

try this, the open handler considers also multiple files.


on run
	set theButton to (display dialog "Please choose from buttons below for path needed:" buttons {"Cancel", "Folder", "File"} giving up after 60)'s button returned
	
	if theButton is "File" then
		set dest to (POSIX path of (choose file) as string)
	else if theButton is "Folder" then
		set dest to (POSIX path of (choose folder) as string)
	end if
	-------
	set the clipboard to dest
	-------
	display dialog dest & " has been saved to Clipboard" buttons "OK" default button 1 with icon 1 giving up after 60
end run
----------
on open theItems
	set thePaths to {}
	set {TID, text item delimiters} to {text item delimiters, "/"}
	repeat with anItem in theItems
		set POSIXPath to POSIX path of anItem
		tell application "System Events"
			set theServer to server of disk (get volume of anItem)
		end tell
		if theServer is not missing value then
			set end of thePaths to theServer & "/" & text from text item 3 to -1 of POSIXPath
		else
			set end of thePaths to POSIXPath
		end if
	end repeat
	set text item delimiters to return
	set the clipboard to thePaths as text
	set text item delimiters to TID
	-------
	display dialog ((count thePaths) as text) & " items have been saved to Clipboard" buttons "OK" default button 1 with icon 1 giving up after 60
end open

I think so, You want you own custom path name? To get the server name of an AFP volume you can use:

getCustomPathOfPosixPath("/Volumes/Share/Folder/file.app")

on getCustomPathOfPosixPath(p)
	if p begins with "/Volumes/" then
		set AppleScript's text item delimiters to "/"
		set serverName to do shell script "mdls -raw -name kMDItemFSName " & quoted form of (text items 1 thru 3 of p as string)
		set p to serverName & "/" & text items 3 thru -1 of p as list as string
		set AppleScript's text item delimiters to ""
	else
		set p to "Localhost" & p
	end if
	return p
end getCustomPathOfPosixPath

Thank you Stefan! That worked beautifully (though I did a facepalm at the simplicity of it). Not enough coffee this morning :rolleyes:

DJ thanks for the help unfortunately when I tried your solution I ended up getting “Share/Share/Folder/File.app.” I am completely ignorant about shell scripting. :confused:

Thanks again!