Hey, so, Doug of Doug's Applescripts for iTunes wrote and explained a template for a collection of applescripts that will help you keep two iTunes libraries on networked computers in sync.
I've been trying to get it working on my computers, and have run into a problem I can't seem to figure out.
In the script, Doug uses a dry run of rsync to get a list of files that are going to be copied in the real rsync, and then uses perl to extract and format the names and paths of the copied files so that the applescript can then have them added to the itunes the library.
I keep getting a syntax error when trying to run the perl shell script. It seems to me to have something to do with the transformations the script performs to create the proper quotes and escapes for the shell script.
The script, up to the point where I'm getting the error is:
The error I get is:
[Eliding the lengthy listing of my entire iTunes library]
Anyone have an idea as to what's going on?
I've been trying to get it working on my computers, and have run into a problem I can't seem to figure out.
In the script, Doug uses a dry run of rsync to get a list of files that are going to be copied in the real rsync, and then uses perl to extract and format the names and paths of the copied files so that the applescript can then have them added to the itunes the library.
I keep getting a syntax error when trying to run the perl shell script. It seems to me to have something to do with the transformations the script performs to create the proper quotes and escapes for the shell script.
The script, up to the point where I'm getting the error is:
Code:
-- == allocate globals
global remUserName, remHostIPAddr, remAddr
-- == init variables
set remUserName to "leo" -- use your remote username
set remHostIPAddr to "192.168.1.5" -- use your remote IP address
set remAddr to (remUserName & "@" & remHostIPAddr) as text
-- use your own remote and local paths to the iTunes Music folders
set locMusicLibrary to "/Volumes/Landingham/Music/iTunes/iTunes Media/Music/"
set remMusicLibrary to "/Users/Leo/Music/iTunes/iTunes Media/Music/"
set locMusicLibraryQuoted to quoted form of locMusicLibrary
set remMusicLibraryEscaped to my replace_chars(remMusicLibrary, " ", "\\ ")
set remMusicLibraryEscapedQuoted to quoted form of remMusicLibraryEscaped
-- == rsync dry run
set theCommand to ("rsync -nEvauz --ignore-existing --exclude '.DS_Store'" & space & locMusicLibraryQuoted & space & remAddr & ":" & remMusicLibraryEscapedQuoted)
set rezList to my text_to_list(do shell script theCommand, ASCII character 13)
log rezList
-- == get file paths
set perlCom to "perl -e'
@rez=(" & (("\"") & my list_to_text(rezList, "\",\"") & ("\"")) & ");
$base=\"" & remMusicLibraryEscaped & "\";
while(1){
$res=shift(@rez);
last unless ($res!~m/.../);
}
while(1){
$res=pop(@rez);
if ($res eq \"\"){last}
}
foreach $z(@rez) {
push (@final,$base.$z.\"\\n\") unless ($z=~m/.\\/$/);
}
print sort @final;
'"
set perlRez to do shell script perlCom
if perlRez is "" then return
set filesToAdd to my text_to_list(perlRez, ASCII character 13)
log filesToAdd
-- == rsync for real
set theCommand to ("rsync -nEvauz --stats --ignore-existing --exclude '.DS_Store'" & space & locMusicLibraryQuoted & space & remAddr & ":" & remMusicLibraryEscapedQuoted)
set rez to (do shell script theCommand)
log rez
-- == add files to iTunes
repeat with fileToAdd in filesToAdd
try
with timeout of (3 * days) seconds
set osaCom to quoted form of ("osascript -e 'tell application\"iTunes\" to add POSIX file \"" & fileToAdd & "\"'")
do shell script ("ssh " & remAddr & space & osaCom)
end timeout
on error m number n
log m
log n
end try
end repeat
-- == end of run ==
-- == handlers == == == == == == ==
on replace_chars(txt, srch, repl)
set AppleScript's text item delimiters to the srch
set the item_list to every text item of txt
set AppleScript's text item delimiters to the repl
set txt to the item_list as string
set AppleScript's text item delimiters to ""
return txt
end replace_chars
on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (theList)
end text_to_list
on list_to_text(theList, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set txt to theList as text
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (txt)
end list_to_text
The error I get is:
Code:
error "sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `perl -e'
@rez=(\"building file list ... done\",\"./\",\"100dbs and Ryan-O'Neil/\",\"100dbs and Ryan-O'Neil/The Adventures of the One Hand Bandit and the Slum Computer Wizard/\",\"13th Floor Elevators/\", ...
Code:
\"that dog_/Totally Crushed Out!/._12 Michael Jordan.mp3\",\"that dog_/Totally Crushed Out!/._13 Rockstar.mp3\",\"\",\"sent 474254 bytes received 17606 bytes 196744.00 bytes/sec\",\"total size is 66132691724 speedup is 134454.30\");
$base=\"/Users/Leo/Music/iTunes/iTunes\\ Media/Music/\";
while(1){
$res=shift(@rez);
last unless ($res!~m/.../);
}
while(1){
$res=pop(@rez);
if ($res eq \"\"){last}
}
foreach $z(@rez) {
push (@final,$base.$z.\"\\n\") unless ($z=~m/.\\/$/);
}
print sort @final;
''" [COLOR="Blue"]number[/COLOR] 2
Anyone have an idea as to what's going on?