use strict;
use Mac::AppleScript qw(RunAppleScript);

sub tell_itunes
{
        my $command = shift;

        my $script = qq(tell application "iTunes"\n$command\nend tell);
        print STDERR "\n", "-" x 50, "\n", $script, "\n", "-" x 50, "\n"
                if $ENV{ITUNES_TELL};

        my $result = RunAppleScript( $script );

        if( $@ )
                {
                die

<<DEATH;
Error in AppleScript: $@
Here is the script that failed:
---
$script
---
 
DEATH

                return;
                }

        return 1 if( defined $result and $result eq '' );

        $result =~ s/^"|"$//g;
	my @result = split /\015/, $result;

        return @result;
}

1;
