Mac GeekeryGet your geek on. |
|
blog advertising is good for you
recent popular content
User login
|
AppleScript is terribly under-used on my computer, so I poked around a little after the last tip and thought about what I could do. I thought about using Scripts in the Script Menu along with my favorite OS feature: assigning arbitrary keyboard shortcuts to menu items. Together, it appeared that they could accomplish much, yes, but what to try? Well, I love how you can set the rating of a group of photos in iPhoto to five stars with ⌘⌥5, and have always wanted the same for iTunes. So, I tried it. I started by making an Automator action as follows:
I saved it as a Workflow document in I then headed over to System Preferences, into Keyboard and Mouse, then to Keyboard Shortcuts. I added an item to set any menu that is called “Rate as 1” to use ⌘⌥1 as the shortcut. After restarting SystemUIServer by forcing it to quit in Activity Monitor, it showed in the Script Menu menu with the proper shortcut (yay!), but no manner of program or system restarts would make it actually activate with the keyboard (boo!). Lesson number one: Script Menu is not in the responder chain for keyboard events. No matter what you set, it won’t take a keyboard command unless you’ve clicked on the menu itself. Even then, if your shortcut involves the option key you’ll trigger the “open the original script” feature rather than executing it. So, Script Menu is out. Psyche. I then looked around and learned of iTunes’ script menu. I dropped the Workflows into tell application "iTunes" repeat with theTrack in (get selection) set the rating of theTrack to 20 end repeat end tell I saved this into that Lesson learned: While you can add anything to the Script Menu, and even give them shortcuts, they won’t work on those shortcuts because SystemUIServer is not a part of the responder chain. Major suck. However, you can add just about anything you would occasionally use in there, so get busy scripting. If you want it to respond to a keystroke, you get to use AppleScript proper and save it in an application-specific folder, presuming that application supports it. To get you started with iTunes AppleScripting, a fellow named Doug appears to have a head start on me with some pretty simple, but useful, ideas. Yes, I’m aware that there are a myriad of programs that let me assign keystrokes to applications and scripts. This, however, is not an article about them. This is about what Mac OS X lets you do.
About Adam Knight
Author Biography Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c. In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon. Bug him over AIM or email [link fixed]. |
Just use the Keyboard Shortcuts tab of the Keyboard & Mouse Preferences pane to add six shortcuts for iTunes. You have to enter the menu name, which is “None” for the 0-star rating, while the other star rating menus use the unicode character “BLACK STAR” U+2605. You can input this character using the character palette utility — or you can copy and paste these: ★★★★★.
(The character palette utility can be found in the “input menu” if you choose “Show input menu in menu bar” in the “Input Menu” tab of the International preference pane.)
Yeah, I thought of that and tried it, but it didn’t work here for some reason.
Anyhow, the idea is more to show that 1) the system UI thinggy is busted for keyboard shortcuts and 2) that iTunes has a scripting menu and how to operate on a batch of files there.
I’ll give the ratings menu another go, though. I’m pretty sure I tried that character but it’s possible I didn’t.
This worked just fine for me. Note that I had to restart iTunes (v7.6) to get the shortcuts activated, but once I did that, it was perfect. And it worked whether I made the keyboard shortcut iTunes-specific or for “All Applications”. Finally, if no song is actively selected, it seems to apply to the one currently playing, which is the behavior I wanted. Thanks for the tip for getting those stars!
Very cool tip. I don’t know much about Applescript, but I wonder if it would be possible to have the script affect the song playing, rather than having to manually select it? I suppose you could do cmd-l, then a rating shortcut, but I think that since this seems to be best used for a currently playing song, it’d be nice to be able to skip the “selecting” step.
I tried both methods, Adams and Adurdin.
Like Adam, it worked from the menu but not the shortcut.
And with Adurdins the shortcut showed up in the iTunes menu, but it didn’t work as a shortcut.
I don’t understand what Adam meant about entering it for ALL applications. How would it know where to look for that menu?
This worked great for me — I was just wondering how the hell I was going to enter the star character into the shortcut menu!
(OS X 10.5.2 / iTunes 7.5)