Can someone figure out why this doesn’t work for me?
set theImage to read (choose file of type "JPEG") as picture
tell application "iTunes"
tell playlist "Library"
set data of artwork 1 of track 1 to theImage
end tell
end tell
This does work:
tell application "iTunes"
tell playlist "Library"
set theImage to data of artwork 1 of track 1
--assuming you manually added artwork to track 1 already
set data of artwork 1 of track 2 to theImage
end tell
end tell
I haven’t tried to script iTunes 4 but maybe looking at the source of Selected Artwork to All In Playlist, by Doug Adams, would be helpful. It copies the artwork from the selected track to all the other tracks in the selected playlist.
Thanks, but this essentially does what the second bit of code I posted does. It copies artwork that has been set manually on one track to other tracks. What I want to be able to do is to identify external images to be assigned by a script to specific tracks. I have a script that reads the track tags then uses that to download an image from the web. I would like to be able to automatically add that image to the track artwork but I haven’t been able to get the last part to work. Reading a file as a picture appears to set it to the same format as the data for the artwork class but iTunes returns an error when I try to assign the image. The code for assigning artwork to a track is fine, it is getting the data from the external file in the proper format that appears to be the stumbling block.
Any additional insight would be greatly appreciated.
I don’t believe the read command ‘knows’ the file is a jpeg file. It normallly reads text and can handle some applescript data formats (records and lists). If I were writing a script to do this, I’d open the jpeg file in a graphics program (e.g., Graphic Coverter but Appleworks will probably do); set the clipboard (or a variable) to the graphic; then set the datafield to the clipboard (or a variable). (May have to use Standard Additions along the way.)
You can set the read command to the appropriate format type:
set theImage to read (choose file) as picture
--> returns PICT
set theImage to read (choose file) as «class JPEG»
--> returns JPEG
set theImage to read (choose file) as «class PNG »
--> returns PNG
set theImage to read (choose file) as «class PDF »
--> returns PDF
but none of these works for the original script. Asking iTunes for the format of artwork for a track where an image has been manually added usually gives «class JPEG» but for some tracks, I get «class PNG » or «class PICT»:
tell application "iTunes"
tell playlist "Library"
return format of artwork 1 of track 1
end tell
end tell
--> «class JPEG»
Trying to read it using an external app such as GraphicConverter doesn’t seem to help.
I would love to have a script to do this. I thought of it the other day, but I haven’t had the time to look into doing it. I hope it works out, because it would be a very cool use of AppleScript, and very handy.
The script Export Artwork, which is also posted here, uses the same “.pict” routines as all the others. No one has been able to maintain the format of the original artwork yet.
The closest I’ve come to the original format, is by copying the data as picture and saving it to a .pict file. If you open the .pict file in Preview, you can export it as .png succesfully whether the original format class is JPEG or PING. Preview will not export it as .jpg.
I thought I had struck gold, but then realised that Preview is not scriptable.
While diZZy’s code is very helpful to get artwork OUT of iTunes, I’m still wrestling with my original problem: getting artwork INTO iTunes. Glad to see Sal is in on it now.
Hello,
Getting pictures into iTunes through AppleScript would be a great idea and it would speed up the process a lot.
One thing I found out is when you drag artwork from iTunes onto the desktop the file it creates is a .clipping file. So I thought that I could easily copy it back into iTunes with applescript. But applescript can not read .clipping files.
–Original question not answered but I figured out the file format is .clipping
–If anyone knows how to read clipping files into applescript that would be nice
set theImage to read (choose file) as picture
tell application "iTunes"
set theP to view of front window
tell theP
set data of artwork 1 of track 1 to theImage
end tell
end tell
I can’t get this to work for me at all. I have upgraded to iTunes 4.0.1 and stil no luck. What type of file are you choosing (JPEG, PICT, etc.)? When I try to read a JPEG as either a JPEG or a picture, I get:
–>iTunes got an error: An error of type -116 has occurred.
If I try to read a PICT as picture, I get:
–>iTunes got an error: Parameter error.
This all using a vanilla MP3 file that I can manually assign either the JPEG or the PICT as the artwork. Has anyone else be able to make this work?
I got it to work by selecting a .pict. Other types, as you discovered, did not work. This particular pict was one that I had exported previously via Preview.
Is using a .PICT still the only way of getting this to work?
Also:
set theImage to read (choose file) as picture
tell application “iTunes”
set theP to view of front window
tell theP
set data of artwork 1 of track 1 to theImage
end tell
end tell
How do I modify this to select a particular playlist - then a particular song before pasting?