– Get the current state of the script, initializing the metadata if necessary
set data_dir to (path to application support from user domain)
set pd to ((quoted form of POSIX path of data_dir) as string) & “iTunes\ Scripts/”
do shell script "mkdir -p " & pd
set cd_file to pd & “current_cd”
do shell script "touch " & cd_file & "; cat " & cd_file
set current_cd to the result
if current_cd = “” then
set current_cd to “Some Author, Some Book, 0”
do shell script "echo " & current_cd & " > " & cd_file
end if
– Loop through multiple CD’s
–repeat
– with timeout of 31000 seconds – i.e. with infinite timeout
– Read the current CD description
do shell script "cat " & cd_file
set current_cd to the result
– Give user a chance to correct the current status
display dialog "Importing - correct this information if necessary " default answer current_cd buttons {“OK”, “Cancel”} default button “OK”
set R to the result
set ok to button returned of R
set current_cd to (text returned of R) as string
if ok = “Cancel” then return
– The author, title, and CD number are separated by commas
set AppleScript’s text item delimiters to “,”
– Extract author and disk number
set author_name to the text item 1 of current_cd
– Compute disk id
set disk_number to the text item 3 of current_cd as integer
if disk_number < 10 then
set diskID to “0” & disk_number
else
set diskID to disk_number
end if
– Compute album name and playlist name
set album_name to the text item 2 of current_cd
set AppleScript’s text item delimiters to {}
set c_count to count of characters of album_name
set album_name to (characters 2 thru c_count of album_name) as string
set playlist_name to album_name
– Save the status, incrementing the disk number
do shell script "echo " & author_name & ", " & album_name & ", " & disk_number + 1 & " > " & cd_file
– Add disk number to album name
set album_name to album_name & " " & disk_number
– Now rip the current CD
tell application “iTunes”
--[i][color=olive] Get the library[/color][/i]
[b][color=blue]set[/color][/b] [color=green]the_library[/color] [b][color=blue]to[/color][/b] ([b][color=blue]get[/color][/b] [b][color=blue]a reference[/color][/b] [b][color=blue]to[/color][/b] [color=blue]library playlist[/color] 1)
--[i][color=olive] Create a playlist for the book if it doesn't exist[/color][/i]
[b][color=blue]if[/color][/b] [b][color=blue]not[/color][/b] ([color=blue]exists[/color] [color=blue]playlist[/color] [color=green]playlist_name[/color]) [b][color=blue]then[/color][/b]
[color=blue]make[/color] [color=blue]new[/color] [color=blue]user playlist[/color] [color=blue]with properties[/color] {[color=blue]name[/color]:[color=green]playlist_name[/color]}
[b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
--[i][color=olive] Initialize track number[/color][/i]
[b][color=blue]set[/color][/b] [color=green]trackNum[/color] [b][color=blue]to[/color][/b] 1
--[i][color=olive] Get the list of tracks on the CD[/color][/i]
[b][color=blue]repeat[/color][/b] [b][color=blue]with[/color][/b] [color=green]i[/color] [b][color=blue]from[/color][/b] 1 [b][color=blue]to[/color][/b] [b][color=blue]the[/color][/b] [color=blue]count[/color] [b][color=blue]of[/color][/b] [color=blue]sources[/color]
[b][color=blue]if[/color][/b] [color=blue]kind[/color] [b][color=blue]of[/color][/b] [color=blue]source[/color] [color=green]i[/color] [b][color=blue]is[/color][/b] [color=blue]audio CD[/color] [b][color=blue]then[/color][/b]
[b][color=blue]set[/color][/b] [color=green]AudioPlaylist[/color] [b][color=blue]to[/color][/b] ([b][color=blue]a reference[/color][/b] [b][color=blue]to[/color][/b] [color=blue]audio CD playlist[/color] 1 [b][color=blue]of[/color][/b] [color=blue]source[/color] [color=green]i[/color])
[b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
[b][color=blue]end[/color][/b] [b][color=blue]repeat[/color][/b]
--[i][color=olive] Rename the tracks[/color][/i]
[b][color=blue]repeat[/color][/b] [b][color=blue]with[/color][/b] [color=green]the_track[/color] [b][color=blue]in[/color][/b] [b][color=blue]every[/color][/b] [color=blue]track[/color] [b][color=blue]of[/color][/b] [color=green]AudioPlaylist[/color]
[b][color=blue]set[/color][/b] [b][color=blue]the[/color][/b] [color=blue]artist[/color] [b][color=blue]of[/color][/b] [color=green]the_track[/color] [b][color=blue]to[/color][/b] [color=green]author_name[/color]
[b][color=blue]set[/color][/b] [b][color=blue]the[/color][/b] [color=blue]album[/color] [b][color=blue]of[/color][/b] [color=green]the_track[/color] [b][color=blue]to[/color][/b] [color=green]album_name[/color]
[b][color=blue]set[/color][/b] [b][color=blue]the[/color][/b] [color=blue]genre[/color] [b][color=blue]of[/color][/b] [color=green]the_track[/color] [b][color=blue]to[/color][/b] "Books & Spoken"
[b][color=blue]set[/color][/b] [color=green]first_word[/color] [b][color=blue]to[/color][/b] [b][color=blue]the[/color][/b] [b][color=blue]first[/color][/b] [color=blue]word[/color] [b][color=blue]of[/color][/b] [color=green]album_name[/color]
[b][color=blue]if[/color][/b] [color=green]trackNum[/color] < 10 [b][color=blue]then[/color][/b]
[b][color=blue]set[/color][/b] [color=green]trackID[/color] [b][color=blue]to[/color][/b] "0" & [color=green]trackNum[/color]
[b][color=blue]else[/color][/b]
[b][color=blue]set[/color][/b] [color=green]trackID[/color] [b][color=blue]to[/color][/b] [color=green]trackNum[/color]
[b][color=blue]end[/color][/b] [b][color=blue]if[/color][/b]
[b][color=blue]set[/color][/b] [color=green]new_name[/color] [b][color=blue]to[/color][/b] [color=green]first_word[/color] & "-" & [color=green]diskID[/color] & "-" & [color=green]trackID[/color]
[b][color=blue]set[/color][/b] [b][color=blue]the[/color][/b] [color=blue]name[/color] [b][color=blue]of[/color][/b] [color=green]the_track[/color] [b][color=blue]to[/color][/b] [color=green]new_name[/color]
[b][color=blue]set[/color][/b] [color=green]trackNum[/color] [b][color=blue]to[/color][/b] [color=green]trackNum[/color] + 1
[b][color=blue]end[/color][/b] [b][color=blue]repeat[/color][/b]
--[i][color=olive] Import the tracks
–
– This is where it is giving the timeout error
–[/color][/i]
with timeout of (1 * hours) seconds
convert the tracks of AudioPlaylist
end timeout
--[i][color=olive] Copy the tracks into the book's playlist[/color][/i]
[b][color=blue]repeat[/color][/b] [b][color=blue]with[/color][/b] [color=green]the_track[/color] [b][color=blue]in[/color][/b] [b][color=blue]every[/color][/b] [color=blue]track[/color] [b][color=blue]of[/color][/b] [color=green]AudioPlaylist[/color]
[b][color=blue]set[/color][/b] [color=green]the_track_ref[/color] [b][color=blue]to[/color][/b] ([b][color=blue]get[/color][/b] [b][color=blue]a reference[/color][/b] [b][color=blue]to[/color][/b] [color=blue]track[/color] ([color=blue]name[/color] [b][color=blue]of[/color][/b] [color=green]the_track[/color]) [b][color=blue]of[/color][/b] [color=green]the_library[/color])
[b][color=blue]copy[/color][/b] [color=green]the_track_ref[/color] [b][color=blue]to[/color][/b] [color=blue]user playlist[/color] [color=green]playlist_name[/color]
[b][color=blue]end[/color][/b] [b][color=blue]repeat[/color][/b]
--[i][color=olive] Eject the CD[/color][/i]
«[color=blue]event[/color] aevtejct»
--[i][color=olive] Wait until another CD is inserted[/color][/i]
(*[i][color=olive] set disk_inserted to false[/color][/i]
repeat until disk_inserted
delay 5.0
repeat with i from 1 to the count of sources
if kind of source i is audio CD then
set disk_inserted to true
end if
end repeat
end repeat
*)
end tell
– end timeout
–end repeat