Re: HFS paths (was Tell Blocks Considered Harmful)
Re: HFS paths (was Tell Blocks Considered Harmful)
- Subject: Re: HFS paths (was Tell Blocks Considered Harmful)
- From: Axel Luttgens <email@hidden>
- Date: Sat, 20 Dec 2008 19:11:27 +0100
Le 20 déc. 08 à 12:54, Chris Page a écrit :
On Dec 20, 2008, at 11:12 AM, Axel Luttgens wrote:
set X to "/System"
(POSIX file X) as text
--> "BootDisk:System"
tell application "Mail" to (POSIX file X) as text
--> "BootDisk:System:"
That's...interesting. If you haven't already, it would be helpful if
you could post a bug report: <http://bugreport.apple.com/>
Although it's odd that the results are different, they are both
valid HFS paths for the System folder (see below).
HFS and POSIX paths that refer to folders/directories do not have to
end with a path separator. If you're concatenating paths you're
responsible for ensuring that you add any missing path separators
between path elements, whether it's an HFS path or a POSIX path.
Just as the HFS paths "BootDisk:System" and "BootDisk:System:" are
equivalent, the POSIX paths "/System" and "/System/" are equivalent.
The discussion went about the rules behind the *production* of paths
by commands, not about the rules for deciding whether paths are
equivalent or not.
It's easier to correctly concatenate POSIX paths than HFS paths,
though. In POSIX paths, consecutive "/" are ignored. "//" is
equivalent to "/", so you can feel free to always add a "/" when
concatenating. In HFS paths, consecutive colons "::" mean "go up a
level", like "../" within POSIX paths, so you have to be careful to
only add them when there isn't already one.
Agreed, defensive programming is always good practice.
And precisely, my point was to illustrate how having a statement
outside or inside a tell block may lead to differing results (and
hence the need for always being prepared to face various special cases).
set X to "/"
(POSIX file X) as text
--> "BootDisk:"
Why suddenly a trailing semicolon?
Because it is required by the HFS path format for volume names.
OK, but then why do I get this one:
(POSIX file "/Volumes/Data") as text
--> "Data"
So, let's have a small recap:
(POSIX file "/System") as text
--> "BootDisk:System"
(POSIX file "/System1") as text -- A non existing item (file or folder)
--> "BootDisk:System1"
(POSIX file "/Volumes/Data") as text
--> "Data"
(POSIX file "/") as text
--> "BootDisk:"
Clearly, the boot disk appears as an exception wrt file -> string
coercion in AppleScript: differing conventions are applied according
to the target. This is perhaps a very desirable behavior, but unless
clearly justified and stated in the language definition, it tends to
appear at least slightly inconsistent.
Axel _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden