KitzKikz  KitzKikz: iTunesBookImport   RecentChanges 
 PopularPages 
 SearchPages 
 Home | Trail - iTunesBookImport
 
 

Description

Requirements

  • iTunes
  • Mac OS X 10.3 or later
  • Mac OS X 10.2 and System Events 1.2 (There was a download, but I can't find it).
  • GUI Scripting enabled

Installation

Put script into ~/Library/iTunes/Scripts

 

Download
BookImportFAQ?
BookImportIssues
History


Click to donate.

 

 

Instructions

 

 

Applescript Source Code

-- Constants
property allOptions : {
    "Book Title", 
    "Author", 
    "Disc Total", 
    "Track Prefix", 
    "Genre", 
    "Join Tracks (Yes/No)"
}

-- Stored Variables (first run only)
property mySettings : {"", "", "", "", "Books & Spoken", "Yes"}
property myDisc : 1

tell application "iTunes"
    activate
    -- Get the library
    set the_library to (get a reference to library playlist 1)

    repeat
        with timeout of 31000 seconds -- i.e. with infinite timeout
            set myChoice to ""
            repeat until myChoice is "Import"
                set dispSet to my buildSet()
                set myChoice to 
                    display dialog ((dispSet as string) & return & "Disc Number") 
                    default answer myDisc buttons {"Stop", "Edit", "Import"} 
                    default button 3
                set myDisc to text returned of myChoice
                set myChoice to button returned of myChoice
                if myChoice is "Edit" then my EditOptions()
                if myChoice is "Stop" then return
            end repeat
            -- Find the CD to import
            -- if none, skip to the eject and wait portion
            set theCD to ""
            repeat with z from 1 to (count of sources)
                if kind of source z is audio CD then
                    set theCD to audio CD playlist 1 of source z
                    set AudioPlaylist to (a reference to audio CD playlist 1 of source z)
                    exit repeat
                end if
            end repeat
            if theCD is not "" then

                -- Set the CD and Track Names and other information
                set diskID to myDisc as number
                if diskID < 10 then set diskID to "0" & diskID
                set name of theCD to item 1 of mySettings
                set artist of theCD to item 2 of mySettings
                set disc number of theCD to myDisc
                set disc count of theCD to item 3 of mySettings
                set genre of theCD to item 5 of mySettings
                set trackNum to 1
                repeat with the_track in every track of AudioPlaylist
                    set trackID to track number of the_track
                    if trackID < 10 then set trackID to "0" & trackID
                    set theName to (item 4 of mySettings) & "_" & diskID & " " & trackID
                    set name of the_track to theName
                end repeat
                if item 6 of mySettings is "Yes" then
                    set theName to (item 4 of mySettings) & "_" & diskID
                    set album of track 1 of AudioPlaylist to theName
                    tell application "System Events"
                        tell process "iTunes"
                            activate
                            set frontmost to true
                            click menu item "Select All" of menu "Edit" of menu bar 1
                            delay 1
                            click menu item "Join CD Tracks" 
                                of menu "Advanced" 
                                of menu bar 1
                        end tell
                    end tell
                end if

                -- Import the tracks
                convert the tracks of AudioPlaylist

                -- Copy the tracks into the book's playlist
                set playlist_name to item 1 of mySettings
                if not (exists playlist playlist_name) then
                    make new user playlist with properties {name:playlist_name}
                end if
                if item 6 of mySettings is "Yes" then
                    set the_track_ref to 
                        (get a reference to track ((item 4 of mySettings) & "_" & diskID) 
                        of the_library)
                    copy the_track_ref to user playlist playlist_name
                    set album of the_track_ref to item 1 of mySettings
                else
                    repeat with the_track in every track of AudioPlaylist
                        set the_track_ref to 
                            (get a reference to track (name of the_track) of the_library)
                        copy the_track_ref to user playlist playlist_name
                    end repeat
                end if
            end if

            -- Eject the CD
            «event aevtejct»

            -- Wait until another CD is inserted
            set disk_inserted to false
            repeat until disk_inserted
                display dialog "Insert next CD" giving up after 8.0 buttons {"Cancel"}
                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
            if theCD is not "" then set myDisc to myDisc + 1
        end timeout
    end repeat
end tell

on EditOptions()
    tell application "iTunes"
    set editChoice to 1
    repeat until ((editChoice is {}) or (editChoice is false))
            set dispSet to my buildSet()
            set editChoice to 
                (choose from list dispSet with prompt "Current book settings:" 
                default items {} with empty selection allowed)
            if ((editChoice is not {}) and (editChoice is not false)) then
                set myEye to my list_position(item 1 of editChoice, dispSet)
                set newVal to text returned of 
                    (display dialog (item myEye of allOptions) 
                    default answer (item myEye of mySettings))
                set item myEye of mySettings to newVal
            end if
        end repeat
    end tell
end EditOptions

on list_position(this_item, this_list)
    repeat with i from 1 to the count of this_list
    if (item i of this_list) is this_item then return i
    end repeat
    return 0
end list_position

on buildSet()
    set dispSet to {}
    repeat with g from 1 to (count of mySettings)
        copy (item g of allOptions) & ": " & (item g of mySettings) 
            & return to end of dispSet
    end repeat
    return dispSet
end buildSet

 

 

Version History  

Version 1.0 (04-Feb-2006)
Initial Version

 

   

 
 EditThisPage · LinksToPage · PageInfo 10/05/09 17:29:58  ·  0.0586s