POSIX file
POSIX file
- Subject: POSIX file
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 05 Oct 2003 13:57:43 -0700
POSIX path, quoted form of POSIX path - both work great.
But POSIX file - the reverse direction from posix path to mac path - has
some problems.
If you receive a POSIX path from somewhere, it will have spaces within the
path escape-backslashed, or else it will be in "quoted form" with single
quotes. Using 'POSIX file" with either of those versions gives the _wrong_
path, and it's no help that there's no error even though this is supposed to
be a file. (Coercing it to alias reveals the errors in the path.) It treats
it just like text, not file - I know this bug has been acknowledged before.
But now I'm just wondering how to do it. If I get a POSIX path for a file on
a non-boot volume, for example, with spaces in the name, it will look like
this:
"/Volumes/PB\ G5\ HD\ Extra/AppleScript\ Studio\
Projects/Clicks/Clicks.pbproj/"
or like this:
"'/Volumes/PB G5 HD Extra/AppleScript Studio
Projects/Clicks/Clicks.pbproj/'"
In this first case, you couldn't even compile that without escaping the
escape backslashes for AppleScript. But that would have normally occurred
already "behind the scenes" like this:
"/Volumes/PB\\ G5\\ HD\\ Extra/AppleScript\\ Studio\\
Projects/Clicks/Clicks.pbproj/"
1. Running
POSIX file "/Volumes/PB\\ G5\\ HD\\ Extra/AppleScript\\ Studio\\
Projects/Clicks/Clicks.pbproj/"
results in
--> file "PB G5 HD Panther:Volumes:PB\\ G5\\ HD\\ Extra:AppleScript\\
Studio\\ Projects:Clicks:Clicks.pbproj:"
which is a non-existent file, as running this shows:
POSIX file "/Volumes/PB\\ G5\\ HD\\ Extra/AppleScript\\ Studio\\
Projects/Clicks/Clicks.pbproj/" as alias
--> ERROR: Can't make file ... into an alias.
2. Running
POSIX file "'/Volumes/PB G5 HD Extra/AppleScript Studio
Projects/Clicks/Clicks.pbproj/'"
results in this:
--> file ":':Volumes:PB G5 HD Extra:AppleScript Studio
Projects:Clicks:Clicks.pbproj:'"
A very weird result, which also is nonexistenet. (Same error 'as alias').
3. If I knew whether the path was even going to have spaces or not, I
suppose I could do a text delimiter replacement of "\\ " by " " and/or "'"
by "" - but the latter might get gummed up if there were an apostrophe is
the path. (For example, an email message or attachment saved to disk might
easily have an apostrophe in the file name.) So then I'd have to specify
just character 1 and character -1 as "'" to be removed. I guess that's the
way to go.
Is there some simpler way to do this? The fly in the ointment seems to be
that the only version of POSIX paths with spaces - not backslashes-escaped,
not quoted - which AppleScript will convert into the real colon-delimited
path of the real file - is illegal in POSIX-land, so it will never ever come
up:
4.
--> POSIX file "/Volumes/PB G5 HD Extra/AppleScript Studio
Projects/Clicks/Clicks.pbproj/" as alias
--> alias "PB G5 HD Extra:AppleScript Studio Projects:Clicks:Clicks.pbproj:"
(Hurray!). To get that from an unknown real POSIXpath in a variable, I'd
have to do this:
5.
set AppleScript's text item delimiters to {"\\ "}
set ls to text items of posixPath
set AppleScript's text item delimiters to {" "}
set posixPath to ls as Unicode text
if character 1 of posixPath = "'" and character -1 of posixPath = "'" then
set posixPath to text 2 thru -2 of posixPath
set theFile to POSIX file posixPath as alias
That should work for all types of POSIX paths, including those with no
spaces. But what a palaver! Shouldn't AppleScript do this for me? The entry
in Standard Additions doesn't seem to have any parameters or coercions for
dealing with file paths with spaces. Or am I missing something?
--
Paul Berkowitz
_______________________________________________
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.