Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

add random artwork to iTunes' songs automatically

Hello Niel (and everyone else),


I have a question....


Well, here goes:


I want to add a different, random image to each of my songs in iTunes.


So, I think this script posted here would be part of it. ( https://discussions.apple.com/thread/2751460?start=0&tstart=0 )


I already have Keyboard maestro to open the "Get Info" menu of any song but that's a dead end for now.


But is there a way to totally automate the process?


To have an applescript pick each song successively and then click "get info" and then click on "artwork" and when the dialog box opens go to a specified folder and chose a random image out of that folder and then finish the dialogue and go to the next song and repeat proces?



thanks for your support


MacBook Pro OSX 10.8

HD: 500 GB

Processor: 2 GHz Intel Core i7

Memory: 8 GB 1333 MHz DDR3

MacBook Pro, Mac OS X (10.6.8), HD: 500 GB

Posted on Sep 3, 2012 8:38 PM

Reply
Question marked as Best reply

Posted on Sep 4, 2012 3:41 AM

Hi,


The script can do this without open the info window.


This script will change the artwork of all tracks from the selected playlist in iTunes window :

-------------------------

globaltheseFiles

set specifiedFolder to choose folder with prompt "Select the folder of images"

tellapplication "Finder" tosettheseFilesto (document filesofspecifiedFolder) asalias list

setnumOfFilestocounttheseFiles


tellapplication "iTunes"

setselPlaylisttoviewoffrontbrowser window

tellselPlaylist

set tc to count tracks

repeat with i from 1 to tc

set data of artwork 1 of track i to my randomImage(numOfFiles)

end repeat

end tell

endtell


onrandomImage(nbr)

setntorandom numberfrom 1 tonbr

read (itemnoftheseFiles) aspicture

endrandomImage

-------------------------

5 replies
Question marked as Best reply

Sep 4, 2012 3:41 AM in response to nimai_pandit

Hi,


The script can do this without open the info window.


This script will change the artwork of all tracks from the selected playlist in iTunes window :

-------------------------

globaltheseFiles

set specifiedFolder to choose folder with prompt "Select the folder of images"

tellapplication "Finder" tosettheseFilesto (document filesofspecifiedFolder) asalias list

setnumOfFilestocounttheseFiles


tellapplication "iTunes"

setselPlaylisttoviewoffrontbrowser window

tellselPlaylist

set tc to count tracks

repeat with i from 1 to tc

set data of artwork 1 of track i to my randomImage(numOfFiles)

end repeat

end tell

endtell


onrandomImage(nbr)

setntorandom numberfrom 1 tonbr

read (itemnoftheseFiles) aspicture

endrandomImage

-------------------------

Sep 4, 2012 6:12 AM in response to Jacques Rioux

Hello Jacques Riox,


This is great! I appreciate this script. Thank you very much.


I did get an error, however.


There are 49 tracks in the playlist and this script set a random image up to track # 35 and then this error occured.



"iTunes got an error: An error of type -206 has occurred."


and this code was highligted when the error occured:


tc

set data of artwork 1 of track i to my randomImage(numOfFiles)


there are 49 tracks in the playlist and this script set a random image up to track # 35 and then the error occured.


thanks for your support,

Sep 4, 2012 9:52 AM in response to nimai_pandit

Hi,


nimai_pandit wrote:


I did get an error, however.


There are 49 tracks in the playlist and this script set a random image up to track # 35 and then this error occured.



"iTunes got an error: An error of type -206 has occurred."


This means that the image format is not valid.

Whether it's a corrupt file, an image format not recognized or it's not an image file.


Here is the modified script, if there is an error "-206", the script will continue with another random as this track will not have a new artwork.


----------------------

globaltheseFiles, BadIndexes, lastIndex

set specifiedFolder to choose folder with prompt "Select the folder of images"

tellapplication "Finder" tosettheseFilesto (document filesofspecifiedFolder) asalias list

setnumOfFilestocounttheseFiles

setBadIndexesto {}

setlastIndexto 0


tellapplication "iTunes"

setselPlaylisttoviewoffrontbrowser window

tellselPlaylist

set tc to count tracks

repeat with i from 1 to tc

set err to 0

repeat

try

set data of artwork 1 of track i to my randomImage(numOfFiles, err)

exit repeat -- no error

on error number theNum

if theNum is not -206 then exit repeat

set err to 1 --the loop continue , apply a new random image for this track

end try

end repeat

end repeat

endtell

endtell


onrandomImage(nbr, n)

ifn = 1 thensetendofBadIndexestolastIndex

repeat

setlastIndextorandom numberfrom 1 tonbr

iflastIndexis notinBadIndexesthenexitrepeat

endrepeat

read (itemlastIndexoftheseFiles) aspicture

endrandomImage

Sep 5, 2012 11:41 AM in response to nimai_pandit

Hi,



nimai_pandit wrote:


did you just make this today? Or did you already have it done?

Yes, but most of the lines in this script are taken in other scripts that I did.

So, the other code are lines according to your specific needs, and error handling.



I have no other links, but here is a link for iTunes scripts : http://dougscripts.com/itunes/.

add random artwork to iTunes' songs automatically

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.