-- **** Daily Maintenance Script -- **** By: Jonathan Wise, Sept 07 set dlFolder to "Theater:Videos:Downloads" as alias set myMusic to alias "Theater:Music:- New Music:" set musicExt to {".mp3"} -- ** Copy music to music folder tell application "Finder" set allFiles to files of dlFolder repeat with theFile in allFiles copy name of theFile as string to FileName if FileName ends with musicExt then move theFile to myMusic end if end repeat end tell -- ** Add new music to iTunes tell application "Finder" set allFiles to files of myMusic repeat with theFile in allFiles copy name of theFile as string to FileName set currSong to theFile as alias if FileName ends with musicExt and the creation date of theFile comes after ((current date) - 1 * days) then tell application "iTunes" add currSong end tell end if end repeat end tell -- ** Clean out downloads folder tell application "Finder" delete (every file of files of dlFolder whose creation date comes before ((current date) - 21 * days)) empty the trash end tell -- ** Update remote iTunes Library and Address Book set oldFolder to "Theater:Information:iTunes" -- This volume is a share, you'd better make sure its mounted before you call it! set oldFolderRoot to "Theater:Information" set newFolder to "Macintosh HD:Users:Wises:Music:iTunes" tell application "Address Book" to quit -- unloads Address Book's database tell application "Terminal" activate do script "ssh media@192.168.1.123" in window 1 -- connect to remote computer delay 4 -- wait for password prompt do script "mypassword" in window 1 -- send password delay 1 do script "osascript -e 'tell app \"iTunes\" to quit'" in window 1 -- quit remote iTunes do script "osascript -e 'tell app \"Address Book\" to quit'" in window 1 -- quit remote Address Book, unloading its database delay 5 tell application "Finder" try delete oldFolder -- delete old library end try delay 2 duplicate newFolder to oldFolderRoot -- copy in current library delay 2 end tell delay 3 -- start remote iTunes, which will automatically sync any connected iPods/iPhones do script "osascript -e 'tell application \"Finder\" to open application \"iTunes\"'" in window 1 -- start remote Address Book, forcing it to re-load its database do script "osascript -e 'tell application \"Address Book\" to activate'" in window 1 do script "osascript -e 'tell application \"System Events\" to set visible of process \"Address Book\" to false'" in window 1 delay 2 do script "exit" in window 1 quit end tell -- start local Address Book, forcing it to re-load its database tell application "Address Book" to activate delay 4 tell application "Address Book" to quit -- tell local iTunes to sync any connected iPods tell application "iTunes" activate update end tell