Jump to content

Rate iTunes Track


Recommended Posts

Just finished a quick workflow to rate the currently playing track in iTunes. Simple usage, type "rate x" where x is the star rating you want assigned to the track. 

 

 

EDIT:

Now supports much better reliability, 1/2 stars, two panel display, and keyboard shortcuts.

 

Latest version can be found here:

 

http://d.pr/f/Oysk

or

https://github.com/dklem/Alfred2-Rate-iTunes-Track

 

 

Screenshots:

 

Rate-iTunes.png?raw=true
 
Rate-iTunes-notification.png?raw=true
Edited by DavidK
Link to post
  • 1 month later...

I had no idea iTunes even supported half stars, though I guess it makes sense based on the X/100 scale iTunes uses for rating. Great, now I'm going to be combing through my iTunes library and re-rating everything!

 

With that said, I updated the extension to support half stars. Seems to work fine, but would appreciate any comments or test cases I might have missed.

 

Latest download links can be found in the top post.

Edited by DavidK
Link to post

David, I just had an idea. Is there a way to add onto your workflow certain ratings that you use a lot and set up shortcuts for those ratings? I use 4, 4.5 and 5 the most; sometimes I use 3 and 3.5. It'd be great to have a faster way to just jump to 4.5 or 5 without having to type rate 4.5. Maybe a keyword of 'rate5' that shows up which can be highlighted and entered. I don't know, maybe its not the smartest thing to do but I thought I'd pass it on to you to see what you think. 

 

Thanks again, been rating like a beast these last few hours. 

Link to post

The newer versions of the Alfred 2 beta now provide a iTunes Commands action, which will allow you to set the rating of a song via a key combination. So, for instance you could set the control-command-4 key combination to rate the current song 4 stars. Unfortunately, the iTunes Commands Actions don't support 1/2 stars. However, the second bash script in my workflow does allow it.

 

You can easily add hotkeys to support any ratings you want, and just link them to my second script like in the picture below: In this example, I used command-option-4 to set to 4 stars.

 

hotkey.png

 

keyconfig.png

 

To address your second request, that's fairly simple as well assuming you don't need half stars. See below for an example:

 

keyword.png

 

 

 

With that said, I've been noticing some slowness and misfires due to the Applescript not completing quick enough. Basically, typing "rate 5" and hitting enter faster than the applescript can run will produce unexpected issues and will not always rate the track properly. (perhaps causing the 1/2 star issues you were seeing) I've got a really good idea to address this, but just need an hour or so to sit down and code it. I'll see if I can work that out later tonight.

 

Dave

Link to post

Okay, updated the script again, and it seems to be significantly more reliable for me. Split out the Information panel from the "Action" panel. Seems that the {query} wasn't being passed correctly unless the applescript finished completely. So, if you are a fast typist, and typed "rate 5" too quick, it wouldn't pass the proper parameter to the rating script. That's all fixed with the 2 panel view noted in the original post.

 

Also, added support for hotkeys to rate the current track. Feel free to set those to whatever feels appropriate for you.

 

Latest (and final?) version can be found in the post at the top.

Edited by DavidK
Link to post

Okay, updated the script again, and it seems to be significantly more reliable for me. Split out the Information panel from the "Action" panel. Seems that the {query} wasn't being passed correctly unless the applescript finished completely. So, if you are a fast typist, and typed "rate 5" too quick, it wouldn't pass the proper parameter to the rating script. That's all fixed with the 2 panel view noted in the original post.

 

Also, added support for hotkeys to rate the current track. Feel free to set those to whatever feels appropriate for you.

 

 

Latest (and final?) version can be found here:

 

http://d.pr/f/ZJsD

or

https://github.com/d...te-iTunes-Track

 

David, instead of multiple posts introducing updates and new features, you would probably be better served to just update the original post with the new update links. The reason is, many people may come to this thread, see the first post with the download link and never scroll down to see the following posts. 

Link to post

David, instead of multiple posts introducing updates and new features, you would probably be better served to just update the original post with the new update links. The reason is, many people may come to this thread, see the first post with the download link and never scroll down to see the following posts. 

Seriously, this is a bit of a problem now. There are so many great workflows that are constantly getting updated but there is not good way of knowing what is the most updated version. I wish there was a way to fix this. 

Link to post
  • 1 month later...

Great script. I rate a lot of songs - my whole library. I would love a version of the script that would skip to the next song if the rating was - say below 3. I tried to modify your script, but I don't know the languafe well enough. Is there anyone who could pose a snippet of code that would work?

 

Thanks.

Link to post
  • 4 weeks later...

Interesting idea. I just tested it, and this code snippet will skip a song if it's rated below 3. Add the code below after the following line in the bash script.

 

"osascript -e "tell application \"iTunes\" to set rating of current track to $rating"

if [[ "{query}" < 3 ]]; then
	osascript -e "tell application \"iTunes\" to next track"
fi
Link to post
  • 4 years later...
  • 2 years later...

I have really enjoyed this workflow and was disappointed when it stopped working with OS X Catalina.

Fortunately, the fix turned out to be really simple...

 

Just replace all instances of

tell application "iTunes"

with

tell application "Music"

Hope this helps.

Randy

Edited by RandyH
Link to post
  • 4 months later...

hello there, 

i saw the randyH's conversation. so i edited here. just copy to paste this :D

 

first. this is "run script"

# Check for proper input value
if [[ "{query}" =~ ^[0-5]\.* ]]; then


	# Check if iTunes is running and playing a song
	if [ $(osascript -e 'if application "Music" is running then return true') ]; then
		iTunesPlaying=$(osascript -e 'tell application "Music" to if player state is playing then return true')
	fi

	if [[ $iTunesPlaying == true ]]; then

		# Grab interesting data for Notification
		infoline=$(osascript -e 'tell application "Music" to "" & album of current track & " by " & artist of current track')
		track=$(osascript -e 'tell application "Music" to name of current track')

		# Get "stars" from numerical value
		case "{query}" in
			0.*) stars="½☆☆☆☆"; rating=10 ;;
			1) stars="★☆☆☆☆"; rating=20 ;;
			1.*) stars="★½☆☆☆"; rating=30 ;;
			2) stars="★★☆☆☆"; rating=40 ;;
			2.*) stars="★★½☆☆"; rating=50 ;;
			3) stars="★★★☆☆"; rating=60 ;;
			3.*) stars="★★★½☆"; rating=70 ;;
			4) stars="★★★★☆"; rating=80 ;;
			4.*) stars="★★★★½"; rating=90 ;;
			5) stars="★★★★★"; rating=100 ;;
			5.*) stars="★★★★★"; rating=100 ;;
			*) stars="• • • • •"; rating=0 ;;
		esac

		# Set rating of the current track to user input
		osascript -e "tell application \"Music\" to set rating of current track to $rating"

		echo "$track  $stars"
		echo "$infoline"
	fi
else
	echo " Rating not Valid
     Nothing modified"
fi

 

second. for "script filter"

## Check if iTunes is running and playing a song
if [ $(osascript -e 'if application "Music" is running then return true') ]; then
	iTunesPlaying=$(osascript -e 'tell application "Music" to if player state is playing then return true')
fi

## If iTunes is playing, start grabbing the data
if [[ $iTunesPlaying == true ]]; then
	valid="yes"
	title=$(osascript -e 'tell application "Music" to "" & artist of current track & " - " & name of current track')
	rating=$(osascript -e 'tell application "Music" to rating of current track')

	## Convert to star ratings
	case $rating in
		10) stars="½☆☆☆☆";;
		20) stars="★☆☆☆☆" ;;
		30) stars="★½☆☆☆" ;;
		40) stars="★★☆☆☆" ;;
		50) stars="★★½☆☆" ;;
		60) stars="★★★☆☆" ;;
		70) stars="★★★½☆" ;;
		80) stars="★★★★☆" ;;
		90) stars="★★★★½" ;;
		100) stars="★★★★★" ;;
		*) stars="• • • • •" ;;
	esac
	
	subtitle="Current rating: $stars"
else
	title="No song playing"
	subtitle=""
	valid="no"
fi


## XML to Alfred
echo '<?xml version="1.0"?><items>'
echo "<item arg=\"{query}\" uid=\"rating\" valid=\"$valid\">"
echo "<title>$title</title>"
echo "<subtitle>$subtitle</subtitle>"
echo "<icon>info.png</icon></item></items>"
echo "</items>"

 

that's all. 

have for fun!

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...