Adding artwork to audio track

Ok, so I’ve given up all hope that I’ll be able to manipulate an mp3 file’s tags outside of iTunes using Applescript so I’ve let go of that desire and decided to just do the work inside iTunes. However, I can’t for the life of me get the artwork code to work. What I’ve got right now is at the bottom of this post (but I’ve tried many many different ways). Basically, I have a picture on my hard drive that I want to use as the artwork for the audio file(s).

The error I’m getting right now is

and it’s failing on the line ‘set myImage to open (jpegFile as file)’. Though, I’ve had many different errors that I can’t remember right now.

I just don’t know what else to do. All the posts and scripts that I found other places on the web are set up exactly like this but I can’t seem to get it to work. Any help here? Thanks!

Script:


set jpegFilename to "/Users/Matthew/Dropbox/photos/avatars/gnpod_album_art.jpg"
set jpegFile to (POSIX file jpegFilename)
tell application "Image Events"
	set myImage to open (jpegFile as file)
	save myImage as PICT in (POSIX file "/Users/Matthew/Dropbox/photos/avatars/gnpod_album_art.pict")
	close myImage
end tell

tell application "iTunes"
	set theArt to read (POSIX file "/Users/Matthew/Dropbox/photos/avatars/gnpod_album_art.pict") from 513 as picture
	if selection exists then
		set sel to a reference to selection
		if class of (item 1 of sel) is file track then
			set theTrack to item 1 of sel
			tell theTrack
                             --there's more stuff in here that manipulates other tags but it all works fine
                             set data of artwork 1 to theArt
			end tell
		end if
	end if
end tell

But why convert from JPEG to PICT??

I’m not really sure why I’m saving as a .pict. I’m pretty new to Applescript and that’s just what every script snippet I found online did, so I did it too.

I’ve updated the script but now I jut get an error message: “iTunes got an error: An error of type -206 has occurred.” on the line where the artwork is being set (‘set data of artwork 1 of theTrack to theArt’). And I haven’t been able to find anyone discussing this anywhere.


tell application "iTunes"
	set theArt to read (POSIX file "/Users/Matthew/Dropbox/photos/avatars/gnpod_album_art.png") from 513 as picture
	log theArt
	if selection exists then
		set sel to a reference to selection
		if class of (item 1 of sel) is file track then
			set theTrack to item 1 of sel
			set data of artwork 1 of theTrack to theArt
			tell theTrack
				--set some other metadata here (it all works)
			end tell
		end if
	end if
end tell

The reason we used to use from 513, is because the pictures were picts and you had to get rid of that stuff at the beginning, and just load the data for the artwork. They don’t use picts now, so they probably made it so you don’t have to do that now.

Editted: BTW, from 513 means your cutting off the first 512 bytes of the file.

gl,

That did it! Yeah, I remember reading that you had to use 513 because that’s where the actual bytes of the picture started but I never thought to get rid of that part for what I need. Thank you so much!

So they did fix it! Thank you also.