I’m trying to send track artwork to Image Events. Is this possible? my code (below) spits this error: “A descriptor type mismatch occurred.” I’m a php buff and programmed (ha) in hypercard back in the day, but know next to nothing about applescript. Any help would be greatly appreciated!
set resultsPlaylistName to "* Missing Artwork"
tell application "iTunes"
-- Get the selected songs in iTunes
set selectedTracks to the selection of front window
-- If no song selected, get all the songs of the selected playlist
if selectedTracks is {} then
try
set selectedPlaylist to view of front window
set selectedTracks to file tracks of selectedPlaylist
end try
end if
tell application "Image Events"
launch
-- Save results to playlist
repeat with thistrack in selectedTracks
if (count artworks of thistrack) is greater than 0 then
-- open the image file
set the_art to artwork of this_track
set this_image to data of the_art
copy the resolution of this_image to {xres, yres}
close this_image
display dialog "Resolution: " & (xres as string)
-- duplicate thistrack to playlist resultsPlaylistName
end if
end repeat
end tell
-- Select the results playlist
-- set view of front window to playlist resultsPlaylistName
end tell
Ciao latitudes,
I have been playing around with a similar problem some time ago and I think one main problem in this operation is that Image Events doesn’t allow you to create a new image from scratch, you have to start from an existing image file. At least this is what it seems to me after a lot of efforts, may be I’m wrong and someone knows a solution?
The following script takes a selected track from an iTunes playlist, rips off the artwork (if there is any), creates a brand new image file with the artwork data and opens it in Image Events to display its resolution. (I didn’t insert a repeat loop for multiple selections as I did not need it for my purpose, but it will be very easy to implement this)
May be it’s useful for you to complete your script:
tell application "iTunes"
set sel to selection
if (count of sel) > 1 then
display dialog "Non puoi selezionare più di un brano." with icon 1
else
set myTrack to item 1 of selection
set n to name of myTrack
set arts to artworks of myTrack
if arts = {} then
display dialog "Il brano \"" & n & "\" non contiene artwork." with icon 1
return
else
set arts to item 1 of arts -- a track can contain multiple artwork; we choose the first one
set imageData to data of arts
my writeImageFile(n, imageData)
end if
end if
end tell
on writeImageFile(n, imageData)
tell application "Finder"
set fileName to (n & ".pict") as string
set myFile to (make new file at desktop with properties {name:fileName}) as alias
open for access myFile with write permission
set eof myFile to 512
write imageData to myFile as picture starting at 513
close access myFile
--open myFile
my getResolution(myFile)
end tell
end writeImageFile
on getResolution(myFile)
tell application "Image Events"
open myFile
set theRes to resolution of image 1
set xres to item 1 of theRes as string
set yres to item 2 of theRes as string
end tell
display dialog "Resolution: " & xres & " x " & yres -- Image Events is a background application that doesn't allow user interaction. Eventual dialogs must be executed outside the Image Events tell block.
end getResolution
As an answer to your questions concerning your code there are 2 or 3 things that wont’t work:
a) the variable artworks has never been defined
b) Image Events doesn’t know anything about tracks and artwork because these are classes and elements of the iTunes suite
c) Image Events won’t display dialogs because it runs always in background
Good scripting
Farid
Thanks Farid, I’ll give it a try!