Need help with path

I have a program that is passing a path to me as follows

file://nsh-sv-fs02/PGH-Jobs_01/5000000/50/500/5000/500000

This is a folder (or file sometimes) on a mounted volume.
For the life of me, I can’t figure out how to get the finder to open this path or write a file to the path. Below is the code I am trying

on main(inputs, outputfolder, params) -- outputfolder is file://nsh-sv-fs02/PGH-Jobs_01/5000000/50/500/5000/500000
	
	set AppleScript's text item delimiters to "file://nsh-sv-fs02" -- remove servername as it is not important
	set path1 to text item 2 of ExamplePath
	set AppleScript's text item delimiters to ""
	set finalPath to "/Volumes" & path1 & "/" -- add volume and end / to file path
	
	tell application "Finder" to open finalPath
	
	
end main

on run
	main(inputs, outputfolder, params)
	return "OK"
end run

Hi,

the Finder needs an HFS path (colon separated), try this


on main(inputs, outputfolder, params) -- outputfolder is file://nsh-sv-fs02/PGH-Jobs_01/5000000/50/500/5000/500000
	if outputfolder starts with "file://" then
		set {TID, text item delimiters} to {text item delimiters, "/"}
		set pathComponents to text items of text 8 thru -1 of outputfolder
		set text item delimiters to ":"
		set finalPath to items 2 thru -1 of pathComponents as text
		set text item delimiters to TID
		
		tell application "Finder" to open item finalPath
	end if
end main

on run
	main(inputs, outputfolder, params)
	return "OK"
end run


try

set myFile to “file://nsh-sv-fs02/PGH-Jobs_01/5000000/50/500/5000/500000” as POSIX file
set myFile to myFile as alias

Your code only works as long as there isn’t any spaces, nor any special characters that gets translated and escaped into the utf8 character set. So if you want a robust solution, that won’t break by a space in folder name, then you really want to use something like this:


set decodedStr to decodefurl(" file://nsh-sv-fs02/PGH-Jobs_01/5000000/50/500/5000/500000")
log decodedStr
--> nsh-sv-fs02/PGH-Jobs_01/5000000/50/500/5000/500000
on decodefurl(anUrlFromABrowser)
	-- 27/08/12 Tested!
	-- converts any escaped chars back to the normal character
	-- removes file, - and local host. 
	local tmpUrl
	
	set tmpUrl to rawURLDecode(anUrlFromABrowser)
	
	set tmpUrl to str_replace({substringToReplace:"file://", replacementString:"", OriginalString:tmpUrl})
	
	if (offset of "localhost" in tmpUrl) is 1 then set tmpUrl to text 10 thru -1 of tmpUrl
	
	return tmpUrl
end decodefurl

on rawURLDecode(str)
	return do shell script "/bin/echo -n " & quoted form of str & " | php -r ' echo rawurldecode(fgets(STDIN)); '"
end rawURLDecode

on str_replace(R) -- Returns modified string
	-- R {substringToReplace: _ent, replacementString: _rent,OriginalString: _str}
	local _tids
	set _tids to AppleScript's text item delimiters
	set AppleScript's text item delimiters to R's substringToReplace
	set _res to text items of R's OriginalString as list
	set AppleScript's text item delimiters to R's replacementString
	set _res to items of _res as string
	set AppleScript's text item delimiters to _tids
	return _res
end str_replace