(* "iTunes Library Mananger" for iTunes written by Chung-Yen Chang (candyz) candyz0416@mac.com Version 0.1 2005/08/26 *) set the iTunesLibraryHome to "$HOME/Music/iTunes" set the iTunesLibraryFile to "\"$HOME/Music/iTunes/iTunes Library\"" as string set the iTunesMusicLibrary to "\"$HOME/Music/iTunes/iTunes Music Library.xml\"" as string set the iTunes_plist to "$HOME/Library/Preferences/com.apple.iTunes.plist" as string set the dbname to "" set the sel to "" set the existdb to do shell script "ls -1d $HOME/Music/iTunes/*.itmf|xargs basename -s .itmf|xargs echo" repeat display dialog "請輸入 iTunes 資料庫的名稱: " & return & existdb default answer "" buttons {"Backup", "Restore", "Delete"} default button 1 copy the result as list to {dbname, sel} if the dbname is not "" then exit repeat end repeat if the sel is "Backup" then --backup set BackupFolder to iTunesLibraryHome & "/\"" & dbname & ".itmf\"" as string do shell script "mkdir -p " & BackupFolder do shell script "/bin/cp -f " & iTunesLibraryFile & " " & iTunesMusicLibrary & " " & iTunes_plist & " " & BackupFolder display dialog "備份完成!!" buttons {"好"} return true else if the sel is "Restore" then --check BackupFolder set BackupFolder to iTunesLibraryHome & "/\"" & dbname & ".itmf\"" as string set the isexistdb to do shell script "ls " & BackupFolder & " && echo Y || echo N" as string if the isexistdb is "N" then display dialog "要復原的資料不存在,請重新確認!" buttons {"好"} return false end if --restore display dialog "要復原 iTunes 資料庫需要先退出 iTunes,現在要退出 iTunes 嗎?" buttons {"Yes", "No"} default button 1 set the toquit to the button returned of the result --quit itunes if the toquit is "Yes" then tell application "iTunes" to quit else --not quit itunes display dialog "復原失敗!需先退出 iTunes 後才能復原。" buttons "好" return false end if --copy files delay 3 do shell script "/bin/cp -f " & BackupFolder & "/iTunes* " & iTunesLibraryHome & "/" do shell script "/bin/cp -f " & BackupFolder & "/com.apple.iTunes.plist $HOME/Library/Preferences/" --launch itunes display dialog "復原完成!現在要開啟 iTunes 嗎?" buttons {"Yes", "No"} default button 1 set the tolaunch to the button returned of the result if the tolaunch is "Yes" then tell application "iTunes" to launch end if return true else if the sel is "Delete" then --delete set BackupFolder to iTunesLibraryHome & "/\"" & dbname & ".itmf\"" as string set the isexistdb to do shell script "ls " & BackupFolder & " && echo Y || echo N" as string if the isexistdb is "N" then display dialog "要刪除的資料不存在,請重新確認!" buttons {"好"} return false end if display dialog "確定要刪除這份 iTunes 資料庫的備份?" buttons {"Yes", "No"} default button 1 set the todelete to the button returned of the result if the todelete is "Yes" then do shell script "/bin/rm -rf " & BackupFolder display dialog "刪除完成!" buttons "好" return true else display dialog "沒有刪除!" buttons "好" return false end if else return false end if