DavidK Posted January 25, 2013 Posted January 25, 2013 (edited) 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: Edited March 3, 2016 by DavidK iansited, surrealroad and DJay 3
DavidK Posted March 8, 2013 Author Posted March 8, 2013 (edited) Updated this to match the default output format used in Notification Center by Alfred for other iTunes actions. Edited March 23, 2013 by DavidK Enhorn 1
scottfwalter Posted March 8, 2013 Posted March 8, 2013 Awesome love this! Don't have to switch to iTunes and can keep my hands on the keyboard. Thanks
morphorod Posted March 10, 2013 Posted March 10, 2013 Great job! I was wondering, is there any way to allow for 1/2 stars like 4.5? That would really make it perfect in my humble opinion. Anyways, great job and I hope to see more workflows soon.
DavidK Posted March 10, 2013 Author Posted March 10, 2013 (edited) 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 March 23, 2013 by DavidK
morphorod Posted March 11, 2013 Posted March 11, 2013 Seems to work fine right now. A couple songs wouldn't take the half star but that was in a small minority of test cases. All in all its a solid workflow. Thank you so much for working it out.
morphorod Posted March 11, 2013 Posted March 11, 2013 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.
DavidK Posted March 11, 2013 Author Posted March 11, 2013 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. To address your second request, that's fairly simple as well assuming you don't need half stars. See below for an example: 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
DavidK Posted March 12, 2013 Author Posted March 12, 2013 (edited) 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 March 23, 2013 by DavidK
Vicia Posted March 14, 2013 Posted March 14, 2013 This is just what I need. Thank you very very much!
naga098 Posted March 22, 2013 Posted March 22, 2013 Just tried this workflow, works brilliantly. Alfred is an amazing app supported by an amazing communiuty of developers and users.
jdfwarrior Posted March 22, 2013 Posted March 22, 2013 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. morphorod 1
morphorod Posted March 23, 2013 Posted March 23, 2013 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.
DavidK Posted March 23, 2013 Author Posted March 23, 2013 Good point David. In this particular workflow, the latest version is linked in the top post as well as the latest github page. I'll edit the other posts in this thread to avoid any confusion.
jdfwarrior Posted March 23, 2013 Posted March 23, 2013 Good point David. In this particular workflow, the latest version is linked in the top post as well as the latest github page. I'll edit the other posts in this thread to avoid any confusion. Awesome, thank you sir
dp1207 Posted April 26, 2013 Posted April 26, 2013 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.
DavidK Posted May 25, 2013 Author Posted May 25, 2013 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
Awfki Posted May 28, 2017 Posted May 28, 2017 Thanks for this. I added your "next track" line to mine as I'm listening to a playlist of "rating 0" and rating a song removes it from the playlist.
RandyH Posted December 10, 2019 Posted December 10, 2019 (edited) 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 December 10, 2019 by RandyH DavidK 1
Zahir Yu Posted April 10, 2020 Posted April 10, 2020 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now