-- script to digitze CDs to *both* AAC and uncompressed AIFF files -- import CD or selected tracks, save as AAC in iTunes library -- and as AIFF in a parallel directory selected by user (e.g. on an external drive) -- Adapted from several scripts on the net: Rip where you want, Import and Eject, -- and a post that provided the sureFolder() routine. -- The AAC settings used are those from the import preferences (nice). global old_encoder with timeout of 300000 seconds tell application "iTunes" activate if (get version as string) is less than "2.0.4" then display dialog "This script requires you use iTunes version 2.0.4 or better." buttons {"Quit"} error number -128 end if -- Okay to procede copy current encoder's name to old_encoder copy every encoder's name to myOptions set a_CD to false repeat with i from 1 to the count of every source if the kind of source i is audio CD then set name_of_CD to the name of source i as text -- use this as default name of new playlist and album later, also set a_CD to true exit repeat end if end repeat if a_CD then -- if there is something in the CD tray... if name of (get view of front window) is name_of_CD then -- CD hilited? if name_of_CD contains "Audio CD" then set noCDDB to true -- 2006 the first string here got mashed into some weird unicode, had to retype it if (button returned of (display dialog 숀ഀऀऀऀऀऀऀ∀䤀琀 氀漀漀欀猀 愀猀 琀栀漀甀最栀 琀栀攀 䌀䐀䐀䈀 栀愀猀 渀漀琀 戀攀攀渀 焀甀攀爀椀攀搀 昀漀爀 琀爀愀挀欀猀 漀渀 琀栀椀猀 䌀䐀⸀⸀⸀∀ ☀ 爀攀琀甀爀渀 ☀ 爀攀琀甀爀渀 ☀⃂ "Would you like to Quit and do that now?" buttons {"Good idea, Quit now", "No, continue"} with icon 1) as text) contains "quit" then my restore_stuff() error number -128 end if end if set thisCDPlaylist to a reference to (get view of front window) if selection exists then set using_selection to true copy selection to selectedTracks copy (count selection's items) to ix else -- its the whole playlist set selectedTracks to (get a reference to thisCDPlaylist) set using_selection to false copy (count thisCDPlaylist's every track) to ix end if set current encoder to encoder "AIFF Encoder" -- select folder to put ripped tracks in set plural to "" if ix is greater than 1 then set plural to "s" set choose_folder_prompt to ("Choose 'iTunes Music' root folder of other library" & plural & " to...") copy (choose folder with prompt choose_folder_prompt) to L2 if L2 is false then error number -128 -- set AppleScript's text item delimiters to {":"} set L1 to "startup disk:Users:zilla:Music:iTunes:iTunes Music" -- adjust this set n1 to number of text items in L1 -- repeat with i from 1 to ix -- START MAIN REPEAT LOOP if using_selection then copy (item i of selectedTracks) to this_here_track else copy (track i of selectedTracks) to this_here_track end if set current encoder to encoder "AIFF Encoder" try copy (convert this_here_track) to just_ripped_track on error errMs number errNum my alert_and_cancel(errMs & return & errNum) my restore_stuff() end try set current encoder to encoder "AAC Encoder" repeat with a_new_ripped_track in just_ripped_track try copy (convert a_new_ripped_track) to aac_ripped_track -- tconvert to aac on error errMs number errNum my alert_and_cancel(errMs & return & errNum) my restore_stuff() end try end repeat repeat with a_new_ripped_track in just_ripped_track set oldLocation to a_new_ripped_track's location --set dir to (a reference to oldLocation) copy oldLocation to dir set n2 to number of text items in (dir as text) set ndir to "" repeat with j from (n1 + 1) to (n2 - 1) set tok to text item j of (dir as text) set ndir to ndir & tok set ndir to ndir & ":" end repeat set ndir to (ndir as string) -- collapse list --set ndir to ndir & ":" -- folder should end in a : log ("concatenating L2 = " & L2) log ("concatenating ndir = " & ndir) set ndir to L2 & ndir set ndir to ndir as string -- ndir has a :: in it set k to offset of "::" in ndir set ndir2 to text 1 thru k of ndir set ndir2 to ndir2 & (text (k + 2) thru -1 of ndir) log ("ndir = " & ndir) log ("ndir2 = " & ndir2) my sureFolder(ndir2) tell application "Finder" try move oldLocation to folder ndir2 delete oldLocation -- if ndir2 is on a second volume it is not deleted on error errMs display dialog errMs end try end tell delete a_new_ripped_track end repeat end repeat tell application "iTunes" activate end tell say "done digitizing" -- this weird thing ejects the cd -- hidden characters look like << >> -- 2006 had to replace this with just "eject" 윀攀瘀攀渀琀 愀攀瘀琀攀樀挀瓈 -- display dialog "Done!" buttons {"Thanks"} default button 1 with icon 1 giving up after 30 my restore_stuff() else my alert_and_cancel("CD is not selected in Source window!") end if else my alert_and_cancel("No CD currently loaded!") end if end tell end timeout to alert_and_cancel(msg) tell application "iTunes" display dialog msg buttons {"Cancel"} default button 1 with icon 0 giving up after 30 my restore_stuff() end tell end alert_and_cancel to restore_stuff() tell application "iTunes" if old_encoder is not "" then set current encoder to encoder old_encoder end tell end restore_stuff on sureFolder(strPath) log ("called sureFolder(" & strPath & ")") if (offset of ":" in strPath) is 0 then return false --not a path if strPath ends with ":" then set isFolderPath to true set strFile to "" if strPath is not ":" then set strPath to text 1 thru -2 of strPath set pathList to PathToList(strPath) set strPath to strPath & ":" else set isFolderPath to false set pathList to PathToList(strPath) set strFile to item -1 of pathList set pathList to items 1 thru -2 of pathList set strPath to ListToPath(pathList) end if tell application "Finder" if folder strPath exists then return true else -- proceed to building the path set theDisk to item 1 of pathList log ("sureFolder theDisk " & theDisk) if not (exists alias (theDisk & ":")) then error "No such volume. (" & theDisk & ")" number -35 end if repeat with i from 2 to (count pathList) set strParentPath to my ListToPath(items 1 through (i - 1) of pathList) set strFolderPath to my ListToPath(items 1 through i of pathList) set strFolderName to item i of pathList log ("making " & strFolderName) if not (exists alias strFolderPath) then make new folder at alias strParentPath with properties {name:strFolderName} end if end repeat end if end tell return strFile end sureFolder on PathToList(strPath) set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" try set pathList to every text item of strPath on error set pathList to {} set AppleScript's text item delimiters to oldDelims end try set AppleScript's text item delimiters to oldDelims pathList end PathToList on ListToPath(pathList) set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" try set strPath to pathList as string on error set strPath to "" set AppleScript's text item delimiters to oldDelims end try set AppleScript's text item delimiters to oldDelims strPath & ":" end ListToPath