Re: Q about coercion to POSIX file
Re: Q about coercion to POSIX file
- Subject: Re: Q about coercion to POSIX file
- From: Christopher Nebel <email@hidden>
- Date: Thu, 30 Oct 2003 10:10:43 -0800
On Oct 30, 2003, at 7:49 AM, Brennan wrote:
I'm having some confusion with the coercion 'as POSIX file'.
Based on what you're trying, you appear to have the functions of "POSIX
file" and "POSIX path" backwards. Here's how it actually works:
1. AppleScript has "file" and "alias" objects. The various
file-related scripting additions all take or return these; for
instance, "path to" returns an alias object.
2. "file" and "alias" objects have a "POSIX path" property, which
returns the POSIX path string for that file or alias. For example:
path to "apps" --> alias "Macintosh HD:Applications:"
POSIX path of the result --> "/Applications"
This is mainly useful for feeding file objects to "do shell script".
3. POSIX file -- which is really a pseudo-class, not a coercion -- is
used to go the other way. You can specify a "POSIX file" by name,
where the name is a POSIX path string, and you get a regular "file"
object that points to that file. For example:
set p to "/Applications"
POSIX file p --> file "Macintosh HD:Applications:"
The point here is that "POSIX file" is only for translating POSIX path
strings into file objects. It's not a proper class, and is not
required for anything else.
There's some additional weirdness: first, the "POSIX path" property
also works on strings. It wasn't supposed to, but it shipped that way,
and people started relying on it before we could rip it out, so now
it's there for good. Second, you can use both "POSIX path" and "POSIX
file" on paths that don't really exist. It will then take a best guess
based on translating colons to slashes or vice versa. Therefore, if
you, say, ask for the POSIX path of a string that already *is* a POSIX
path, it's going to do something weird. Your example was this:
POSIX path of "test/hello"
That's a valid relative HFS path; "POSIX path" assumes that it's in the
root directory, and since it has a slash, it will need to translate
that to a colon (since slashes are not allowed in POSIX file names for
obvious reasons), so you get "/test:hello". "POSIX file" does much the
same thing, but in reverse. It's logical, but not useful.
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.