Stories
Slash Boxes
Comments
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by pudge (1) on 2003.12.03 19:28 (#26281) Homepage Journal
    This is just crying to be rewritten using Mac::Glue. :-)
    #!/usr/local/bin/perl
    use warnings;
    use strict;
     
    use Mac::Glue ':all';
     
    my $itunes = new Mac::Glue 'iTunes';
     
    $itunes->activate;
     
    my $lesson = $itunes->display_dialog(
        'Enter the lesson:', default_answer => ''
    )->{text_returned};
     
    my $playlist  = $itunes->prop(view => window => 1);
    my @selection = $itunes->prop('selection')->get;
    my @tracks = @selection
        ? @selection
        : $playlist->obj('file_tracks')->get;
     
    my @sublist = ('a' .. 'k');
     
    for my $i (1 .. @tracks) {
        my $track = $tracks[$i - 1];
        $track->prop('artist')->set(to => "Robert Greenberg");
        $track->prop('album')->set(to => "How To Listen To And Understand Great Music");
        $track->prop('name')->set(to => "Lesson $lesson $i");
    }
     
    __END__
    There's a slight bug somewhere in the new UTF handling in Mac::Glue that causes the artist and album to show up incorrectly in iTunes. I have what I think is a fix (checking Encode::is_utf8() before sending data to iTunes as Unicode) for the next version, but I am not altogether comfortable with it. Odd that iChat doesn't have the same problem with the same data when I send to it; I suspect iTunes might be handling it incorrectly.

    Regardless, until the next version of Mac::Glue, you can do:
    to => param_type(typeChar(), "Robert Greenberg"))