Re: It can not be only me...
Re: It can not be only me...
- Subject: Re: It can not be only me...
- From: Mr Tea <email@hidden>
- Date: Sat, 06 Dec 2003 17:29:33 +0000
This from Deivy Petrescu - dated 6/12/03 2.55 pm:
>
Posix path!!!! (loud sound of my banging my forehead!)
Paul Berkowitz posted a discussion of posix issues in this forum a little
while back. A trimmed version is appended below. Should I assume that
nothing has changed in Panther?
--------What PB Said--------
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. 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/"
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.
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, also non-existent.
I could do a text delimiter replacement of "\\ " by " " and/or "'" by "" -
but the latter might get gummed up if there were an apostrophe in the path.
So then I'd have to specify just character 1 and character -1 as "'" to be
removed. 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:
--> 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:
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
end if
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?
--------------------------------
Thanks for that, BTW, Paul. I found it in the archives when playing with
posix paths recently, and it's a very concise and useful reference.
Nick
pp Mr Tea
_______________________________________________
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.