Re: Scripts works with OSX 10.5 but not earlier because of Unicode
Re: Scripts works with OSX 10.5 but not earlier because of Unicode
- Subject: Re: Scripts works with OSX 10.5 but not earlier because of Unicode
- From: Paul Taylor <email@hidden>
- Date: Fri, 11 Apr 2008 21:05:08 +0100
Christopher Nebel wrote:
On Apr 10, 2008, at 1:43 PM, Paul Taylor wrote:
Hi, I have a script that now works fine on OSX 10.5 (Applescript 2?)
but fails on 10.4 and earlier when the filename contains unicode
characters. This ties in with this link
http://www.apple.com/applescript/features/unicode.html, it seems I
have to use the Unicode text class but I cant work out to use it so
that it works on 10.5 and 10.4
Please help Im guessing this is quite trivial for regular applescript
developers but not for me.
(in the script below the problem is the ǿ at the end of bee)
tell app "iTunes"
set new_playlist to (make user playlist with properties
{name:"Jaikoz:4/10/08 1:31 PM"})
add(POSIX file "/Users/paul/Music/iTunes/iTunes Music/beeǿ/A Hard
Days Night/When I Get Home.mp3") to new_playlist
repeat with nexttrack in (get every track of new_playlist)
refresh nexttrack
end repeat
end tell
So, the script you're running is literally the text above, with that
"ǿ" in there?
Yes, I create the file above and then pass it as the only argument to
osascript
If so, then the problem you're running into is that AppleScript
pre-10.5 doesn't handle Unicode text literals like that -- it
transcodes everything into an old-style encoding, and I don't think
any of them support that particular character.
There are a few possible solutions:
1. Write the string as a raw data literal instead, something like this:
«data utf868656C6C6F20776F726C64» as Unicode text --> "hello world"
«data ut1600680065006C006C006F» as Unicode text --> "hello"
If you couldn't tell, that's "utf8" or "ut16" followed by the UTF-8 or
UTF-16BE data for the text, as hex. Both of those will work on Tiger;
I can't swear to anything earlier. ("ut16" almost certainly won't;
you can use "utxt", but then you have to be careful about endianness.)
Ok, I understand your example but not how to put it into script ,could
you change the script line please.
2. Write the string data to a file as Unicode, and then read it from
there. Not necessarily practical, depending on how dynamic this whole
scheme is, but it would work.
I would have to create two files, the script and a data file. Actually
could be a nice solution in that I just create the script once, and then
just recreate the data file each time I have some new files to process.
But given a datafile containing:
/Users/paul/Music/iTunes/iTunes Music/beeǿ/A Hard Days Night/When I Get
Home.mp3
/Users/paul/Music/iTunes/iTunes Music/beeǿ/A Hard Days Night/file2.mp3
...
written as utf8
what would be script look like to process it.
If I recall an earlier message of yours correctly, you're actually
generating this script and executing it from another program. In that
case, a third possibility would be to make that program do the iTunes
work itself, rather than delegating it to AppleScript. This will
depend on what the original language is, but most languages that run
on Mac OS have some sort of Apple Event support. Since you want this
to run on 10.4, your best bet is probably appscript, which is a
third-party library; I'd suggest Scripting Bridge, which is part of
Mac OS, but only in Leopard.
Your'e right, Im using Java , on Windows I use COM but to my knowledge
on OSX is pretty basic and Applescript was the only thing/easiest thing
I could find.
Paul
_______________________________________________
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