Re: alias as string = as Unicode text?
Re: alias as string = as Unicode text?
- Subject: Re: alias as string = as Unicode text?
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 19 May 2002 11:32:20 -0700
On 5/19/02 10:15 AM, "John W Baxter" <email@hidden> wrote:
>
At 19:58 -0700 5/17/2002, Paul Berkowitz wrote:
>
> Since alias format now works with file and folder names in Unicode, what
>
> happens when you coerce an alias 'as string'? According to Script Debugger,
>
> the result is "international text": is that as good as Unicode in this
>
> context?
>
>
Almost certainly not. "International Text" is a pre-Unicode (pre wide
>
adoption of Unicode by Apple) format; type is "itxt". Value is some
>
leading bytes giving the "script" (the other meaning of script: Roman,
>
etc) and language, followed by the data.
>
>
Check the result in Script Debugger using the AEPrint formatting.
>
>
If the Unicode names are expressible in the old "itxt" format, then it's
>
possible that a coercion of the itxt string to Unicode text would produce
>
useful Unicode. But not if the itxt format can't hold the information...eg
>
an outer folder name is in French and another folder name is in
>
Chinese...the whole "itxt" string is in one langauge within one script, and
>
clearly that example doesn't fit.
>
>
I don't have any samples to work with, so all of the above (except the
>
"International Text" layout info) is from thought experiments.
>
Well, let me put it another way. You can get the names of every disk,
folder and file in the path to some file in the Finder, and the results will
all be in Unicode. Set variables to each of them: myDisk, firstFolder ,
secondFolder , theFile. You can concatenate all these Unicode names together
with colons "as Unicode text" :
set filePath to (myDisk & (":" as Unicode text) & firstFolder & (":"
as Unicode text) & secondFolder & & (":" as Unicode text) & theFile) as
Unicode text
Now you've got a bona fide Unicode path with the actual names, no matter how
many scripts or languages were used along the way.
set unicodeAlias to alias filePath
That will work, since all alias formats are Unicode now. (You can just set a
regular old file path string "as Unicode text", then alias it, and it's just
the same as aliasing the string version; you get that funny 12-pt geneva
type when you compile.)
Now, how do you get the original path back out of that?
set stringPath to unicodeAlias as string
gets you just the "international text" version, and not the original you
started with. Unless, unknown to us, that formula is perhaps actually now
producing Unicode? (Doubtful.)
I'm wondering how you'd get the thing in Unicode when you're starting from
the alias. You could plunk into the Finder and coerce it a a Finder file,
but unless you know how many folders there are along the path, it would be
tricky, although feasible, to work it out. You'd keep asking for the
container of the file until you got a disk. Something like this:
to unicodizeAlias(theAlias)
tell application "Finder"
set unicodePath to name of theAlias
set theItem to theAlias
repeat
set theContainer to container of theItem
set containerName to name of theContainer
set unicodePath to (containerName & (":" as Unicode text) &
unicodePath) as Unicode text
if class of theContainer is disk then
exit repeat
else
set theItem to theContainer
end if
end repeat
end tell
return unicodePath
end unicodizeAlias
That actually works. But it would be a lot nicer if we could instead simply
set unicodePath to theAlias as Unicode text
I think a new coercion along these lines is needed, no?
T
--
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.