Re: One Finder and one iTunes Question?
Re: One Finder and one iTunes Question?
- Subject: Re: One Finder and one iTunes Question?
- From: Skeeve <email@hidden>
- Date: Tue, 08 Apr 2008 13:30:59 +0200
Philip Aker wrote:
1. Munge the array returned into a list of urls. Something like:
Is it an array with more than one entry for you? I never encountered
more than 1 yet.
set dblist to paragraphs of (do shell script "/usr/bin/defaults read
com.apple.iApps iTunesRecentDatabases | tr -d '(' | tr -d ')' | tr -d
'\"' | tr -d ' ' ")
2. Translate the urls into POSIX file paths
set dblist to paragraphs of (do shell script "/usr/bin/defaults read
com.apple.iApps iTunesRecentDatabases | perl -ne " & quoted form of "
if (m#\"file://localhost([^\"]+)#g) {
$_= $1;
s/%(..)/pack 'H2',$1/ge;
print qq($_\\n);
}
")
3. cp each file path to an easy location like /tmp/db1.plist
or link it. It's faster than copying.
ln -s ...path..here... /tmp/x.plist
4 Use 'defaults' to read the output files (in the form /tmp/db1)
defaults read /tmp/x 'Music Folder'
5. Translate those urls into file paths.
Ugh! AppleScript needs some built-in URL encoding and coercion handlers.
Okay... Here we go:
set dblist to paragraphs of (do shell script "/usr/bin/defaults read
com.apple.iApps iTunesRecentDatabases | /usr/bin/perl -e " & quoted form
of "
use File::Temp qw/ tempfile /;
my($fh, $templist)= tempfile( SUFFIX => '.plist' );
while (<>) {
foreach (m#\"([^\"]+)\"#g) {
$_= fileURL_to_filename($1);
unlink $templist;
link $_,$templist;
my ($plist)= $templist;
$plist=~ s/\\.plist$//;
$_= `/usr/bin/defaults read $plist 'Music Folder'`;
tr/\\015\\012//d;
print fileURL_to_filename($_);
unlink $templist;
}
}
sub fileURL_to_filename {
local($_)= shift;
s#file://localhost(?=/)##;
s/%(..)/pack 'H2',$1/ge;
return $_;
}")
This will give you for each Music Library XML found, the associated
current Music Folder as a POSIX Path.
_______________________________________________
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