Hello. I post my heavy duty, which aren't tested in a project yet. It have been tested in the debugger. Thanks to Yvan, it handles quotes within quoted paths. You should be able to feed it with *anything* (that exists) It also considers "~" and disks/volumes. Maybe you can use this? script PathWay
on hfsPathOfAnythingAsText(anyFileOrFolderPath) -- returns the full hfs pathname of anything if the files exists local tids, theFile, lastItem, tidsToUse, singleQuoteCheck -- Thanks to Yvan Koenig :) set singleQuoteCheck to false set tidsToUse to ":" try (get class of anyFileOrFolderPath) on error number -1728 -- it was a filereference set fileOrFolderPath to fileOrFolderPath as alias as text return fileOrFolderPath end try set anyFileOrFolderPath to "" & anyFileOrFolderPath -- doesn't harm. if anyFileOrFolderPath starts with "'" and anyFileOrFolderPath ends with "'" then set anyFileOrFolderPath to text 2 thru -2 of anyFileOrFolderPath set singleQuoteCheck to true end if if anyFileOrFolderPath does not start with "/" and anyFileOrFolderPath does not start with "~" then return anyFileOrFolderPath -- we had a hfspath
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, tidsToUse} set anyFileOrFolderPath to text items of anyFileOrFolderPath as text if singleQuoteCheck is true then set AppleScript's text item delimiters to "'\\''" set anyFileOrFolderPath to text items of anyFileOrFolderPath -- as list set AppleScript's text item delimiters to "'" end if -- if tidstouse was "/" then we must add the disk name, - but which ??? set anyFileOrFolderPath to "" & anyFileOrFolderPath set AppleScript's text item delimiters to tidsToUse if text item 1 of anyFileOrFolderPath is "~" then set anyFileOrFolderPath to text items 2 thru -2 of (POSIX path of (path to home folder) as text) & text items 2 thru -1 of anyFileOrFolderPath else if text item 2 of anyFileOrFolderPath is "Volumes" then set anyFileOrFolderPath to text items 3 thru -1 of anyFileOrFolderPath else set anyFileOrFolderPath to {item 1 of (list disks)} & text items 2 thru -1 of anyFileOrFolderPath end if set AppleScript's text item delimiters to ":" set anyFileOrFolderPath to "" & anyFileOrFolderPath set AppleScript's text item delimiters to tids return anyFileOrFolderPath end hfsPathOfAnythingAsText
end script |