• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: One Finder and one iTunes Question?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: One Finder and one iTunes Question?
      • From: Philip Aker <email@hidden>
    • Re: One Finder and one iTunes Question?
      • From: Skeeve <email@hidden>
References: 
 >One Finder and one iTunes Question? (From: Dave <email@hidden>)
 >Re: One Finder and one iTunes Question? (From: Skeeve <email@hidden>)
 >Re: One Finder and one iTunes Question? (From: Philip Aker <email@hidden>)

  • Prev by Date: Re: do shell script hanging
  • Next by Date: Re: One Finder and one iTunes Question?
  • Previous by thread: Re: One Finder and one iTunes Question?
  • Next by thread: Re: One Finder and one iTunes Question?
  • Index(es):
    • Date
    • Thread