Re: Converting Unix path to AppleScript path
Re: Converting Unix path to AppleScript path
- Subject: Re: Converting Unix path to AppleScript path
- From: Matt Deatherage <email@hidden>
- Date: Mon, 27 Mar 2006 23:18:02 -0600
On 3/27/06 at 5:31 PM, Stockly, Ed <email@hidden> wrote:
> I'm hoping there's a one line solution out there... anyone?
Nope, but there's a prewritten solution for you. Google is your
friend. First, visit here:
<http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.10.htm>
Copy the last two routines, "on decode_chars" and "on decode_text",
into your script.
Then visit this page:
<http://www.codecomments.com/archive262-2004-10-308769.html>
.and see Michelle's wise solution. Put these together:
> set myURL to my
> decode_text("file:///Volumes/Mag_Production/Color Lab Images/03:
> 26/Issue #9 prepressed/tm.0326.chinaRS.tiff")
< "file:///Volumes/Mag_Production/Color Lab Images/03:26/Issue #9
< prepressed/tm.0326.chinaRS.tiff"
[I inserted the line breaks]
> set text item delimiters to "/" return (text items 3 through end of
> myURL) as text as POSIX file
< file "Herbie G5:Volumes:Mag_Production:Color Lab Images:03/26:Issue
< #9 prepressed:tm.0326.chinaRS.tiff"
Note, of course, that my hard drive is named "Herbie G5" so it got
introduced into the path. Also note that AppleScript took care of the
":" and "/" problem for you.
(for those who don't know: since "/" is permitted in HFS pathnames but
is the POSIX path delimiter, the Carbon File Manager routines that deal
with pathnames substitute colons for actual slashes in POSIX pathnames.
Since there can't really be a colon there on an HFS disk, the system
knows it's supposed to be a slash. Note that when the system converted
it back to an HFS-style path, the slash was restored.)
The result will work with any file URL, not just the ones you've run
into so far, and returns an actual AppleScript "file" object. You can
then use it as a file, cast it to an alias, or have whatever file fun
you want. Clean and supportable.
--Matt
--
Matt Deatherage <email@hidden>
GCSF, Incorporated <http://www.macjournals.com>
"People say the glass is half full, but they don't say of what."
-- Sourpuss, "Dilbert," 2005.12.10
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden