Page 1 of 1

Get iTunes Metadata AppleScript [v0.2]

Posted: Wed Jan 30, 2008 5:48 am
by sbooth
Here is version 0.2 of an AppleScript to pull a CD's metadata from iTunes and import it into Max.

To use it, first copy and paste the code below into Script Editor and save the file as a script of some sort. Next, launch Max and iTunes and insert the CD. Once iTunes has obtained the CD's information from GraceNote, run the script and the metadata will populate to Max.

Code: Select all

tell application "iTunes"
	set foundCD to true
		set myCD to some source whose kind is audio CD
	on error errorMessage number errorNumber
		-- error 1728 means the AudioCD was not found, so wait a little 
		if errorNumber is -1728 then
			set foundCD to false
			display dialog errorMessage
		end if
	end try
	if foundCD then
		set CDname to myCD's name
		set myPlaylist to playlist 1 of myCD
		set theTracks to tracks of myPlaylist
		tell application "Max"
			set mc to (count every track of document 1)
			set maxdisk to document 1
		end tell
		set ic to (count theTracks)
		if mc = ic then
			repeat with i from 1 to (count theTracks)
				set atrack to item i of theTracks
				set ar to artist of atrack
				set al to album of atrack
				set tn to track number of atrack
				set tc to track count of atrack
				set ge to genre of atrack
				set co to composer of atrack
				set ye to year of atrack
				set na to name of atrack
				set comp to compilation of atrack
				set com to comment of atrack
				set dn to disc number of atrack
				set dc to disc count of atrack
				tell application "Max"
					set maxtrack to track i of document 1
					if not (rip in progress of maxtrack) and not (encode in progress of maxtrack) then
						set title of maxtrack to na
						set artist of maxtrack to ar
						set date of maxtrack to ye as string
						set genre of maxtrack to ge
						set composer of maxtrack to co
						--set number of maxtrack to tn
					end if
				end tell
				if i = 1 then
					tell application "Max"
						set title of maxdisk to al
						set artist of maxdisk to ar
						set compilation of maxdisk to comp
						set genre of maxdisk to ge
						set date of maxdisk to ye as string
						set composer of maxdisk to com
						-- set track count of maxdisk to tc
						-- max doesn't allow setting total tracks
						set composer of maxdisk to co
						if dn > 1 then
							set disc number of maxdisk to dn
							set total discs of maxdisk to dc
						end if
					end tell
				end if
			end repeat
			display dialog "The iTunes CD track count and the Max CD track count do not match."
		end if
		display dialog "Couldn't get a CD from iTunes. Please retry."
	end if
end tell

Re: Get iTunes Metadata AppleScript [v0.2]

Posted: Sun Mar 16, 2008 3:18 pm
by sbooth
Version 0.2 fixes the problem setting total discs.