The task: to make a hot key, in which the desired rating for a playing song would be set in iTunes, as a bonus - a mass setting of the rating for several songs. Solution: since we have only 5 rating options (this is an interface, in fact, a gradation from 0 to 100), we will need to write 5 AppleScript scripts and hang our hot key on each script.
Below is a generic script that allows you to put down a rating for the following situations:
if one track is selected, the rating is affixed for it. Note: if the selection cursor is on one track and plays another, then the rating will be set for the playing track;
if several tracks are selected, the rating is set for each selected one.
else if ((trackCount = 0) or (trackCount = 1)) then
set the rating of playingTrack to Rate_5
end if
end tell
In order to make 5 scripts, simply substitute the desired value from the Properties block into the script you need. In order to hang the script on the hotkey, do the following:
create a folder / Library / iTunes / Scripts /
we copy in it 5 created scripts
go to "System Preferences - Keyboard & Mouse - Keyboard Shortcuts" and create five hot keys, the names of which exactly match the names of your scripts *
open iTunes and notice Script Menu at the top with our scripts and hotkeys for them.
* for some machines it is necessary to restart the SystemUIServer process after step 3