vanclute Posted May 30, 2015 Share Posted May 30, 2015 I thought for sure this would be so basic as to have a simple tutorial or section in the help documents, but I couldn't find any such thing nor could I find anyone discussing how to do it. I have an existing Applescript (one of Doug's Applescripts for iTunes) that allows for rating iTunes songs via a menu. But I'd like to be able to rate via keyboard shortcuts, so that while working and a song comes up I can just quickly flick a key combo and bam - rated. No mousing, selecting, or reading required. So what I need to do I believe is set up 5 hotkeys (for ratings 1 to 5 stars) and pass the typed value to the applescript and act accordingly. I see that by default the hotkey is apparently passed through to the workflow, but then what? How do I access that variable in the Applescript? Thanks in advance! Link to comment
FroZen_X Posted May 30, 2015 Share Posted May 30, 2015 Hello vanclute, it would be easier to help you, if you could provide the Applescript/Workflow you're using right now. That way its easier to tweak what you have or let you know what has to be changed. Cheers, Frozen Link to comment
deanishe Posted May 31, 2015 Share Posted May 31, 2015 AFAIK, a workflow can't receive keypresses because they aren't Mac apps: the keypress events will be sent to Alfred instead. You probably want to connect each of your 5 hotkeys to 5 Run Script actions, each of which calls your AppleScript with the appropriate arguments for that rating. Link to comment
FroZen_X Posted May 31, 2015 Share Posted May 31, 2015 @deanishe thats why i was asking for the workflow itself, that way it can be tweaked for his needs The working workflow can be split up to be used or different hotkey combos can pass through different arguments. Cheers, Frozen Link to comment
vanclute Posted May 31, 2015 Author Share Posted May 31, 2015 Well there is no workflow currently, that's what I'm trying to create. The Applescript in question is here: http://dougscripts.com/itunes/scripts/ss.php?sp=ratethissong I just want to assign keyboard shortcuts so that I can instantly rate a song without having to see a dialog, choose a rating, and click a button. One keystroke and the song is rated based on whatever I typed (like CTRL-1 through CTRL-5, or something) Thanks for any assistance! Link to comment
deanishe Posted May 31, 2015 Share Posted May 31, 2015 (edited) One way to do what you want is as follows: 1. Add a Hotkey Trigger for each rating, e.g. CTRL+1, CTRL+2 etc.2. Each Hotkey should have Action set to "Pass through to workflow" and Argument set to "Text". Finally, set the Text field of each Hotkey to the appropriate rating (i.e. 1, 2, 3, 4, 5, or 0): 3. Add a Run Script action with Language set to "/usr/bin/osascript" and paste the following in the Script box: set newRating to "{query}" as integer tell application "iTunes" if player state is not playing then log "Nothing playing" return end if set currentTrack to current track set currentRating to ((rating of currentTrack) / 20) log "Current Rating : " & (currentRating as string) & " New Rating : " & (newRating as string) if newRating = currentRating then log "Rating unchanged" return end if set rating of currentTrack to (newRating * 20) return "Set rating to " & (newRating as string) end tell 4. Connect all of your hotkeys to this action. The workflow should now work as desired (but only when a track is playing). Optionally, you can add a Post Notification Output with Title (or Text) set to "{query}" and select the Only show if passed in argument has content option. This will then show "Set rating to X" when a track's rating is changed. Edited May 31, 2015 by deanishe Link to comment
deanishe Posted May 31, 2015 Share Posted May 31, 2015 (edited) As an addendum: iTunes stores ratings internally as numbers between 0 and 100, which is why I divide the track's current rating by 20 and multiply the new rating by 20 before setting it. 10, 30, 50 etc. correspond to half-star ratings, i.e. 70 = 3.5 stars, 90 = 4.5 stars. The "log" statements will show up in Alfred's debugger. Any text returned will be passed to the next action as {query} (if there is a next action). Edited May 31, 2015 by deanishe Link to comment
vanclute Posted May 31, 2015 Author Share Posted May 31, 2015 Awesome, that's exactly the concept I was going for but didn't know how to do with Applescript. I'll look into implementing what you've posted here... thanks again!! Will reply again if I run into any issues. Link to comment
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