So a little while back I had a thread where you guys helped me make a custom level indicator that was basically a rating indicator that had bigger easier to see stars. (using images) I have it check for the rating of the song in iTunes and fill out appropriately. That works perfect. Now for some reason (since Leopard) I can no longer set the stars…nothing happens when I click in it. IT’s connected to my script…its named properly…its selected as editable. What am I doing wrong here? This is the short code that I have that is supposed to set the stars.
on setstars()
set therate to ((content of control "ri" of window "main") as integer) * 20
tell application "iTunes"
try
set rating of current track to therate
on error
display dialog "Before you rate a song you have to play one!"
end try
end tell
end setstars
on setstars()
set therate to 3 * 20
tell application "iTunes"
try
set rating of current track to therate
on error
display dialog "Before you rate a song you have to play one!"
end try
end tell
end setstars
setstars()
I’ve tried it and it seems some internal mouse tracking behaviour of the rating NSLevelIndicator has been modified for 10.5. You probably have noticed that it now has some new features (no longer limited to 5 stars etc.) - so it’s most likely that it has been partially rewritten. In my test I could set the rating only by clicking in the very left part of the custom level indicator when using large star sizes. If this is correct, it’s probably necessary to implement your custom mouse handling in the cell. A similar cell class where I used …
sure thing Dom, your a life saver (as usual ), I just found out that all school buses have been cancelled so I don’t have to go to school today, so im gunna get a few extra hours of sleep
We’re getting closer, now I don’t know if this is the Obj-C or the applescript conflicting but say the current song is 4 stars. I can actually change the number of stars but it lasts for like a millisecond and then goes back to four stars…
it must be an applescripting conflict then. Obviosuly to set the stars i should just call the method in an on clicked handler. What about getting the stars. What handlers should I call that method from?
well the float value won’t always be 3.5 right? It will be whatever they click on the level indicator.
These are the 2 sub-routines I’m using:
on getstars()
tell application "iTunes"
try
set starnum to (rating of current track) div 20
on error
set starnum to 0
end try
end tell
set float value of control "ri" of window "main" to starnum
end getstars
on setstars()
set therate to (float value of control "ri" of window "main") * 20
tell application "iTunes"
try
set rating of current track to therate
on error
display dialog "Before you rate a song you have to play one!"
end try
end tell
end setstars
I call the setstars in an on clicked handler and the getstars in the on idle handler
hmm - probably I misunderstood. I thought you wanted to know how to set & get the rating programmatically. Now from what you wrote I assume it’s more that you need to know how to catch a user input with our custom level indicator - right?
You used a ‘custom view’ in Interface Builder?
Then this was for example possible by connecting your level indicator to an ‘on mouse up’ handler and modify the mousehandling code of the cell like this: