#!/usr/bin/perl use strict; $|++; use warnings; use Mac::Glue qw(:all); my $itunes = Mac::Glue->new("iTunes"); my $dir = shift; die "specify directory on command line\n" unless ( $dir and -d $dir ); my $playlist = $dir; $playlist =~ s/\///g; $playlist =~ s/\s+/_/g; die "no playlist found\n" unless ($playlist =~ m/[a-zA-Z]/); # check the playlist total time to see if the playlist exists already. # $pl_time will be null if playlist doesn't exist, "0:00" for empty playlist my $pl_time = $itunes->obj(playlist=>$playlist)->prop('time')->get; if ($pl_time) { print "playlist exists!\n"; } else { $itunes->make(new => 'playlist', with_properties => { name => $playlist }); } opendir DIR, $dir or die $!; # only adding songs m4a, m4b, and mp3s. my @file_list = grep { /(mp3|m4[ab])$/i } readdir (DIR); foreach my $file (@file_list) { print $file, $/; # add files to playlist. $itunes->add("$dir/$file", to => $itunes->obj(playlist=>$playlist)); # remove original unlink "$dir/$file" or warn $!; }