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: Chris Page <email@hidden>
- Date: Sat, 20 Dec 2008 03:54:12 -0800
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.
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.
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. Let's
see if I can correctly recall all the rules from the dark corners of
my old Mac programmer brain.
HFS Path Format ("..." indicates zero or more characters):
1. "Name" - A simple name with no colons indicates a file or folder in
the current working directory.
2. "Name:..." - One or more colons indicates a path. A name preceding
the first colon is a volume name.
3. "...:Name" - A name following the last colon is a file or folder
name.
4. "...:Name:..." - Names between colons are, naturally, folder names.
(3 & 4 effectively make the colon optional after the last folder name
in a path.)
5. ":..." - A colon with no preceding name indicates the current
working directory. This is like "./" at the start of a POSIX path.
6. "...::..." - Two consecutive colons indicates the container at that
point in the path. This is like "../" in a POSIX path.
--
Chris Page
The other, other AppleScript Chris
_______________________________________________
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