I’m building a script for rating my itunes playlist. This script give a star (rating 20) to every track, three stars (rating 60) if track has genre “Soundtrack” and five stars (rating 100) if the track has group “Matteo” (yes, Matteo it’s me
This script works fine but is too much long (on my G4, my iTunes has 6600 tracks, and it needs 20-25 minutes).
here you are the script
tell application "iTunes"
set mainLibrary to library playlist 1
set totalTracks to count of file tracks of mainLibrary
repeat with t from totalTracks to 1 by -1
try
set this_track to file track t of mainLibrary
set rating of this_track to 20
if this_track's genre is "Soundtrack" then
set rating of this_track to 60
end if
if this_track's group is "Matteo" then
set rating of this_track to 100
end if
end try
end repeat
end tell
display dialog {"Process completed!"} buttons {"OK"} default button 1 with icon 1
Does anyone have any idea for quick those operation?
tell application "iTunes"
script o
property L : library playlist 1
end script
set rating of tracks of o's L whose grouping is "Matteo" to 100
set rating of tracks of o's L whose genre is "Soundtrack" to 60
set rating of tracks of o's L whose rating is not 100 and rating is not 60 to 20
end tell
display dialog {"Process completed!"} buttons {"OK"} default button 1 with icon 1
Note: each of the three “rating” lines throws an error, if no tracks with its condition are found
Also, if Stefan’s still is to0 slow for you (filter reference forms are slow in iTunes), you could try the if then else form.
if this_track’s genre is “Soundtrack” then
set rating of this_track to 60
else if this_track’s group is “Matteo” then
set rating of this_track to 100
else
set rating of this_track to 20
end if
but what I like to do to really speed things up with iTunes is to use its built in functions.
You could set things up. Make smart playlist with genre is “Soundtrack”, grouping is “Matteo”, and playlist is not the other two smart playlists. Then you could just set the rating of every track in each of these playlist which will be reflected in the Library playlist. This sidesteps the slowness of the filter reference form, you don’t need to repeat though everytrack, and uses iTunes built in capabilities. It just takes a few minutes or seconds to set things up.
tell application "iTunes"
(* 1 star to all *)
set mylist to playlist 1
set rating of every track of mylist to 20
set esistenza to true
(* 3 stars to Soundtrack *)
if not (exists user playlist "Soundtrack") then
set esistenza to false
(* make new user playlist with properties {name:mylist, smart:true, genre:"Soundtrack"}*)
end if
if esistenza is true then
set mylist to user playlist "Soundtrack"
set rating of every track of mylist to 60
end if
(* 5 stars to Matteo *)
if not (exists user playlist "Matteo") then
set esistenza to false
(* make new user playlist with properties {name:mylist, smart:true, grouping:"Matteo"}*)
end if
if esistenza is true then
set mylist to user playlist "Matteo"
set rating of every track of mylist to 100
end if
end tell
You can see that the command “make new user playlist” is under comment. I’ve read that smart playlist are read only in iTunes (also in 7, right?). This script is very, very faster, but it needs that the playlists existance is true.
If Apple will give us full control of iTunes with AS, this versione will be perfect.
That is right. I haven’t thought of a workaround yet to make smart playlists, so it needs to be done manually. I’ll try to think up a workaround again and write back if I find one.
So, i’ve tried.
StefanK’s script seem not to works so good. No errors found, but the script goes out of time.
In the end, all Soundtrack files have 3 stars, but not all Matteo files have 5 stars.
Thank for support: I’ll continue to try other solution tomorrow, I promise to post final script, if I’ll find it
I changed the script for higher priority of the “Matteo condition”
and added a function to avoid the timeout
tell application "iTunes"
script o
property L : library playlist 1
end script
with timeout of 10000 seconds
set rating of tracks of o's L whose genre is "Soundtrack" to 60
set rating of tracks of o's L whose grouping is "Matteo" to 100
set rating of tracks of o's L whose rating is not 100 and rating is not 60 to 20
end timeout
end tell
display dialog {"Process completed!"} buttons {"OK"} default button 1 with icon 1
The script work as I suspect.
In the end, Stefank’s script is good, but I suspect that the problem is that iTunes support for the function “if/then/else” si very bad.
I’m learning AS, and I want to developing scripts that can run in any Mac supported. So, for this one, my best choice is forget playlist and insert if/then/else (Stafank mode is more good than mine).
But, after many time spent to try those scripts, I come back to the first one, where I can assign rating to a playlists istead of a tracks.
On my G4, working with tracks need 10 minutes, working with playlist only 15 second (!!!). This is not the right mode to develop, I know, because if the script don’t find the playlist it doesn’t work, but time difference is too hight.
My hope is a new version of iTunes (7.x, in this MacWorld?), that include an AppleScript support like others Apple iApps.