Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

  (email not shown publicly)
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Tuesday November 20, 2001
10:56 PM

Coercion is Good

[ #1328 ]
So I have this little MacPerl script that gets the current track info on my MP3 player (SoundJam) using Apple events. I also added some logic so that if SoundJam was not running locally, it would check the other machine in the room, using Apple events via TCP/IP with that remote machine. All fine and good.

The problem: I installed iTunes 2 on a couple of machines, and I figure, hey, iTunes is based on SoundJam, so it should work the same. But they changed it so iTunes 2 returns this data in UTF-16 ("utxt"), instead of regular 8-bit text ("TEXT"). I don't have the requisite Perl modules to convert at this point, but I shouldn't need them, because there are corecion handlers in Apple events that will coerce data from one type to another.

In theory, and according to the docs, it should work fine to just do (in AppleScript):

  set songname to name of current track as string

Or in Perl:

  my $song = $sj->get($sj->prop(name => of => 'current track'), as => 'string');

But this wasn't working. After trying to work around it (including by just stripping the high byte, which works for my purposes :-), I remembered there was a new development version of AppleScript available (the AppleScript library contains the Apple event code). I installed it, and it worked (as soon as I added a coercion from "utxt" to "TEXT" in the Perl code).

Bah. So I wasted a lot of time, but got it to work.

NP: A Place Of Springs - Phil Keaggy (Beyond Nature)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.