Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Control iTunes from the keyboard Apps
How many times has the phone rang, and you've either had to dive for the mute button (on Extended keyboards), the volume knob, or iTunes itself? What a pain, particularly when you're in another application. Wouldn't it be nice if you could control iTunes using dedicated keyboard keys, like some programmable PC keyboards let you control Windows applications?

I haven't seen anyone using this exact method of controlling iTunes, and it seems to me to be one of the best and most intuitive. There are any number of AppleScripts and menu items available on the web, but none of them fit my needs. I tend to make large playlists and let them shuffle. My tastes in music being very broad, I often want to skip a particular song, or replay one I just heard, depending on the mood and/or occasion.

Requirements:Either macro program lets you put custom commands onto the menu bar as well as trigger them via keystrokes (my preferred method). The bare minimum commands, in my opinion, are listed below. It's easy to add more. I use function keys F10, F11, and F12. With modifiers, many more commands are within easy reach of the right hand.

I've tested this with both Youpi Key and QuicKeys, and it is not within the scope of this hint to suggest which you should use. I'll demonstrate with Youpi Key as it is free; QuicKeys has a downloadble time-limited demo that can be used as well.

In the Youpi Key Editor, I added a new Shortcut: Run Script. I named the command "iTunes Play/Pause", assigned it F10, and entered...
tell application "iTunes"
playpause
end tell
...in the script window. Works like a charm, anywhere, anytime, instantly. Hitting it once starts a stopped or paused iTunes, launching it if necessary; hitting it again pauses iTunes, if playing. I also added scripts (to keys F11 and F12) that are almost identical: instead of "playpause", however, they say "previous track" and "next track", respectively.

Interestingly enough, this works even if a screen saver is running, at least with Youpi Key. If you normally password-protect your screen saver, be careful what scripts you attach as macro to keys! The screen saver will continue to run, however, so it would be hard to do much damage without access to the desktop or GUI.

The final step to complete this effort at further automating iTunes requires iTunes Notifier. This fades in a floating window (customizable by you) for a preset (short) time with the name of the current track. This works well for me because I don't often remember the names and/or artists of music I don't listen to frequently. It's unobtrusive and can be made translucent, so it doesn't have to obscure your work. I find myself glancing at it only if I need to know the name of the song. Before I found this program, I had to switch back to iTunes via the Dock to find out the name of the currently playing song.

[Editor's note: You can, of course, use iTunes' contextual menu in the dock (control-click on the dock icon) to do exactly what this hint describes, but that would require using the mouse. It's nice to have a keyboard-only alternative.]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[34,532 views]  

Control iTunes from the keyboard | 37 comments | Create New Account
Click here to return to the 'Control iTunes from the keyboard' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Keyboard Maestro
Authored by: Fofer on Thu, Nov 21 2002 at 11:16AM PST
Worth mentioning is Keyboard Maestro which now has iTunes control support. It's got a lot of QuickKeys-esque functionality, such as mapping mouse movement, selecting menus, and more. Also has a nice application switcher. I use it to replace 3 or 4 other utilities, and it works well.

[ Reply to This | # ]
Yipee for Youpi!
Authored by: jjckanellis on Thu, Nov 21 2002 at 11:17AM PST
Great hint. I've used KeyXing and Dragthing to automate various keystrokes but this may be the one to use from now on. Although I purchased Dragthing I find little use for it these days except to run some scripts. Launchbar (or just using the dock better) has pretty much replaced Dragthing for me for all its other uses. KeyXing is brilliant but I stopped using it after the trial period and have been contemplating purchasing the shareware license. Youpi certainly seems worth trying for a while.
JK


[ Reply to This | # ]
More Controls
Authored by: jonathanmcd on Thu, Nov 21 2002 at 11:20AM PST
I thought this sounded like a great tip, and tried it right away. One thought I had is that sometimes I want to adjust iTunes volume without affecting the system volume, so I whipped up these quick additions:

tell application "iTunes"
set x to sound volume
set sound volume to (x + 5)
end tell

tell application "iTunes"
set x to sound volume
set sound volume to (x - 5)
end tell

I attached them to function keys, and voila! Works great!

[ Reply to This | # ]
More Controls
Authored by: bluehz on Thu, Nov 21 2002 at 11:45PM PST
These also work for volume control - raising and lowering iTunes volume only in +/-10 increments.

tell application "itunes"
set sound volume to sound volume + 10
end tell

and

tell application "itunes"
set sound volume to sound volume + 10
end tell

[ Reply to This | # ]
More Controls
Authored by: bluehz on Thu, Nov 21 2002 at 11:56PM PST
This will toggle mute off/on:

tell application "iTunes"
if mute is false then
set mute to true
else
set mute to false
end if
end tell

Wierd thing is - mute is not even mentioned in the iTunes Applescript dictionary.

[ Reply to This | # ]
More Controls
Authored by: bluehz on Fri, Nov 22 2002 at 12:37AM PST
If you install the iTunes Notifier - you can also script it to pull up theinfo on command:

In Youpi Key - Run Unix Command:
/Path/to/Library/PreferencePanes/PTHiTunesNotifier.prefPane/Contents/MacOS/PTHiTunesNotifier.app/Contents/MacOS/PTHiTunesNotifier &

(cmd above all on one line)

Now if I could just figure out how to get it to display the second line of a stream...for instance Radio Paradise toggles the display between the standard Radio Paradise blurb and the current song title/artist. For some reason iTunes Notifier will only display the Radio Paradise blurb, never the actual song title/artist.

Also mute is in the dictionary - under Application

[ Reply to This | # ]
More Controls
Authored by: Jimmy Flamenco on Fri, Nov 22 2002 at 2:42AM PST
Instead of the if-then construction you can just type

tell application "iTunes"
set mute to not mute
end tell

[ Reply to This | # ]
Blank Keys
Authored by: encro on Thu, Nov 21 2002 at 12:09PM PST
Great hint!
Now where do we get some unprinted keys to replace the F-Keys with?

Maybe a hardware developer could make an add-on usb control board with about 10 User configurable keys on it. Now that would be fantastic.

[ Reply to This | # ]
Blank Keys
Authored by: MtnBiker on Thu, Nov 21 2002 at 12:34PM PST
In a way DragThing and QuicKeys (the two I've experience with, but the other mentioned would do the same I presume) can create extra keys, by using unlikely key combinations. I'm in the same boat as the original author, so i assigned

Control-Option-Command End to Pause/Start
Control-Option-Command UpArrow to volume up
Control-Option-Command DownArrow to volume down

That may seem like an awful combination until you look at a full size keyboard, but it's easy. I picked this combination because the arrows made sense and end was nearby and seemed like stop. And the ones the author picked I long ago (ten years or more with QuicKeys and since in OS X with DragThing) assigned to application launching. Also one can't pick combination used by other programs (and you'd be amazed how many there are and how easy it is to forget they exist until you use one in that program and something else happens because you assigned that combo with DragThing or some other macro program).

Thanks for the hint, the main part for me was having the AppleScript written. I can never read a dictionary and figure out how to do something.

[ Reply to This | # ]
AppleScript and iTunes
Authored by: MtnBiker on Thu, Nov 21 2002 at 2:17PM PST
Contrary to what I said above, I could understand the iTunes Dictionary and was able to add next track.
But most still don't make sense. To confirm this I went to the IE dictionary to see if one could tell how to open a URL in a new window. Not obvious to me that:
OpenURL theURL toWindow 0
is how to do this.

[ Reply to This | # ]
Blank Keys
Authored by: Myrddin on Fri, Nov 22 2002 at 9:08AM PST
Personally I have a Logitech Internet Navigator keyboard. I have 21 keys that can be programed and a scroll wheel, most of the buttons are already set and labeled for your common functions. The important part of this blurb is that at the top, in the middle, are a section of keys that give me direct control over iTunes functions: launching the app, play/pause, stop, forward/back, mute, and volume up/volume down.

The software from Logitech is still rough in some places but it will give you a choice from any of their keyboards, mice or combos.

[ Reply to This | # ]
Awesome Hint
Authored by: ibnabouna on Thu, Nov 21 2002 at 12:09PM PST
Thanks, the volume one was also great.

Does anyone know which function keys can safely be modified without interfering with the system or other programs?

[ Reply to This | # ]
Awesome Hint
Authored by: Jay on Fri, Nov 22 2002 at 12:34PM PST
F12 is used to eject media on newer g4s when used with any keyboard that doesn't have an eject key.

[ Reply to This | # ]
Or try X-tunes
Authored by: lebowski on Thu, Nov 21 2002 at 12:23PM PST
http://www.pol-online.net/index.php?page=freewares

This allows you to set any key combination to bring up a transparent controller for iTunes.
No matter what i'm doing, just press apple+space and i can change song, volume etc...

enjoy!

L.

[ Reply to This | # ]
Fun with arrow keys
Authored by: G-Mantle on Thu, Nov 21 2002 at 12:33PM PST
I've been using Keyboard Maestro to control iTunes for a few months now and I highly recommend it. I used to use the F-keys, but recently I switched over to using the arrow keys and some modifiers because it's a bit more intuitive. Here's my suggested list of shortcuts:

ctrl-left/right - previous/next track
ctrl-up/down - volume up/down
cmd-ctrl-left - rewind track
cmd-ctrl-right - next track and increment play count
cmd-ctrl-up - full volume
ctrl-space - play/pause

[ Reply to This | # ]
X-Tunes
Authored by: Jay on Thu, Nov 21 2002 at 12:31PM PST
You should look into X-Tunes. It displays a keyboard-shortcut transparent floating window with lots of track information and controls that can be used with the mouse or keyboard. I've used many iTunes remotes, but this one is the only one that meets all my needs.

[ Reply to This | # ]
X-Tunes
Authored by: Accura on Thu, Nov 21 2002 at 9:53PM PST
X-Tunes doens't handle its self very well at all, IMHO not worth looking at

[ Reply to This | # ]
X-Tunes
Authored by: Jay on Fri, Nov 22 2002 at 12:32PM PST
Well, it's worked perfectly for me. I don't understand what you mean by "it doesn't handle itself well."

[ Reply to This | # ]
X-Tunes
Authored by: Accura on Thu, Apr 10 2003 at 12:09AM PDT
It munched down CPU like photoshop on drugs, was quite crasy, i was runnin git on a g3 under 10.1 or the PB. i cant remember but it was SLOOOW

---
"The time has come," the walrus said. "To talk of many things..."

[ Reply to This | # ]
Most of all...
Authored by: Ezekiel on Thu, Nov 21 2002 at 1:00PM PST
I'd like a Logitech keyboard with those special keys (both for music and other stuff) that lots of PC people are using. They work like a charm with OS X too, and what could be more intuitive than pressing a play/pause button to play/pause? :-)

But great hint nontheless, I'm gonna look over the different solutions, though not any of those involving more than one key. The whole point with this is getting very fast and easy access to play/pause, volume and next track (I usually have iTunes set to play random from my Library, and sometimes I really don't want to hear a song that comes on, so I'd like to have a quick way of skipping it).

[ Reply to This | # ]
this hint kicks ass
Authored by: cyberwoozle on Thu, Nov 21 2002 at 5:04PM PST
OK, so I've been avoiding AppleScript now forever... but no longer! Youpi is excellent, and the whole inter-application communication thing is bizarre!!!

This isn't just a great hint, it's an eye opener for me to AppleScript, and I've been looking for a track notifier for iTunes for ages, too!!!

[ Reply to This | # ]
iTunes Applescripts
Authored by: tobypadilla on Thu, Nov 21 2002 at 6:24PM PST
Great tip. I use the the Keyspan Media remote to control iTunes, and have found it useful to bind similar scripts to my remote buttons. I also like to use iTunes Notifier when I'm sitting at my computer, but sometimes I like to see what song is playing from the couch. I ended up writting an Applescript that passes the song vars to a php page and opens up Chimera to display it. If anyone is interested in it I've posted it here. You'll need php set up on your machine, and you'll also need to edit the scripts to point at your home directory. There's also a script up that acts as an iTunes alarm clock (when scheduled by cron). It starts iTunes, sets the volume and starts playing songs in a Wake Up playlist. Enjoy.

[ Reply to This | # ]
iTunes Applescripts
Authored by: mkoz on Fri, Nov 22 2002 at 12:57PM PST
the php thing is neat, but what if you can't see your monitor? what if my computer could read my track info, wouldn't that be great, well it can. i made this applescript a while back so i could find out what was playing and not get in my way. here is the applescript:
property volumeLow : 50

tell application "iTunes"
  set t to current track
    
  set ts to name of t
    
  set art to artist of t
  if art is not "" then
    set ts to ts & " - " & art
  end if
    
  set alb to album of t
  if alb is not "" then
    set ts to ts & " - " & alb
  end if
    
  set origVol to sound volume
    
  if (volumeLow is less than sound volume) then
    set sound volume to volumeLow
  end if
end tell

say (ts as string)

tell application "iTunes"
 set sound volume to origVol
end tell
this script collects the track info from itunes, lowers the volume in itunes so you can hear the computer read the info, reads the info, and returns the volume to where it was before. you can change the value of the property volumeLow so itunes is louder or softer while reading the info. i also have this script attached to the pause button on my keyspan dmr. enjoy.

[robg adds: I edited the above script to insert some line breaks to reduce the width of this comment. The actual comment and the script were not changed.]

[ Reply to This | # ]
iTunes Applescripts
Authored by: tobypadilla on Fri, Nov 22 2002 at 6:22PM PST
Wow, that's pretty cool. Fortunately for me my apartment is so small I can see my Cinema HD from anywhere! :)

[ Reply to This | # ]
Speaking iTunes Applescripts
Authored by: GaelicWizard on Wed, Dec 4 2002 at 2:47AM PST
WAY COOL, Thanx!!!

[ Reply to This | # ]
Additions
Authored by: vonleigh on Thu, Nov 21 2002 at 7:11PM PST
Great post, thanks for sharing. I would however like to adjust this tip to my own habbits and am wondering if someone can provide some applescript guidance.

Basically, instead of shuffling through my whole playlist (something that isnt' random at all) I create a smart playlist where playcount == 0. This way when I quit iTunes I don't loose my 'place' in the shuffle, and it becomes alot more random.

Problem is if you skip to the next song, the song stays there in your list. If you skip forward too many times (say nineteen, since I load 20 songs randomly) I get to the end of the smart playlist.

Is there a way so that I could script it to smoething like, make X length of song, set time to X-1? That way it'd jump to the very end of the song, and skip to the next, effectively skipping the song, increasing it's play count, and getting it out of the playlist.

I tried looking at the iTunes dictionary and didn't see anythign appropriate.



thanks,
v

[ Reply to This | # ]
Play count updating...
Authored by: jermudgeon on Wed, May 14 2003 at 5:01PM PDT

This fits the bill, I think: allows you to skip the current track while increasing the playlist.

tell application "iTunes"
	set totalTime to duration of current track
	set player position to (totalTime - 1)
end tell

Stick this line in before "set player position..." to disable the track, too.

	set current track's enabled to false

I keep these scripts (skip forward, skip forward + increase count, skip+increase+disable) assigned to one key, with modifiers. Saves my bacon.



[ Reply to This | # ]
THANKS
Authored by: seven5 on Thu, Nov 21 2002 at 9:22PM PST
this is the best hint in a while, i have been wanting a system wide way of contolling itunes, because just muting isn't good for me, i like to actually pause..

I've just been too lazy to do anything about it i guess...

THANKS for letting me stay lazy!!


[ Reply to This | # ]
AppleScript in HotApp
Authored by: yata on Fri, Nov 22 2002 at 4:48AM PST
Hate to take away some of the glory of a great hint but I went to try this hint out using HotApp and found the apple scripts to the first part of this hint (the Youpi Key part) where already there. It was just a matter of choosing any one of 7 different iTune scripts (incl. play/pause, next song etc), then selecting a function key to make the commands active. Still, it's a very useful hint as I hadn't thought to look there before.
(System Prefs>HotApp>Add Menu>AppleScript)

[ Reply to This | # ]
Keyspan Digital Media Remote
Authored by: anandman on Fri, Nov 22 2002 at 5:06AM PST
In addition to X-Tunes, I also use and highly recommend the Keyspan DMR. The Keyspan software allows running Applescripts so I have access to iTunes from any app. The nice thing about using the remote is that I don't have to be near my PC. I can pause the music, answer the phone, hang up, and start up the music again all without being near my PC (other than within sight of the IR receiver).

I've now setup my iTunes on my PowerBook to access the MP3s on my iMac in my office using a wireless connection. Combine that with the Keyspan DMR receiver/software and my universal remote and now I can hook up the PowerBook to the stereo and TV (for visuals) for a great MP3 jukebox. Tres Cool!

[ Reply to This | # ]
Itunes keyboard trix
Authored by: digitol on Fri, Nov 22 2002 at 7:31AM PST
Am I missing the point here? Couldn't one just press the "mute" key on the keyboard to produce the same effect? Understanding we all don't have the apple extended keyboards of course. Just a thought.


[ Reply to This | # ]
Here is code that will not launch iTunes accidentally
Authored by: Krioni on Fri, Nov 22 2002 at 2:23PM PST
I've used YoupiKeys with AppleScript to do this for a while. Here's a suggestion: it should only playpause if iTunes is already running, so you don't launch iTunes by accident while doing a sales presentation. Here's the code:

tell application "Finder" to if (name of processes) contains "iTunes" then
tell application "iTunes"
playpause
end tell
end if

Also, you can put that "is running?" line in front of the Next Track and Previous Track commands, too:

tell application "Finder" to if (name of processes) contains "iTunes" then
tell application "iTunes"
next track -- or previous track
end tell
end if



[ Reply to This | # ]
Call me different...
Authored by: eno on Sat, Nov 23 2002 at 9:16AM PST
...but I prefer using Synergy.

[ Reply to This | # ]
More ideas for iTunes Scripts?
Authored by: DougAdams on Sat, Nov 23 2002 at 3:03PM PST
Don't forget to stop by! Doug's AppleScripts for iTunes

[ Reply to This | # ]
Another vote for synergy - Awesome shareware!!!
Authored by: tcurtin on Sat, Jan 18 2003 at 1:36PM PST
Hey all - you should really check out synergy at http://synergy.wincent.org/. Little system prefs panel that puts previous, next, and play/pause buttons in your menubar (so you can always get at them, and you can set them to disappear when iTunes isn't running.) Plus, you can set system-wide hotkeys. I've got mine set to F7 F8 and F9. Plus, its only $5 shareware fee! Great stuff - this now has a place reserved on my top two list of best shareware apps - LaunchBar is at the top. (Another awesome app - if you haven't tried it yet you should - it will completely change the way you move around on your mac!

[ Reply to This | # ]
iTunes Notifier updated
Authored by: mondelicious on Fri, Jan 24 2003 at 5:08PM PST
The new version of iTunes Notifier has added menubar control and hotkeys. This should probably fill the needs expressed in these comments without having to run applescripts. I have also been a happy user of Synergy, but I guess I won't need it anymore... mondelicious

[ Reply to This | # ]
Rewind & fast forward
Authored by: jermudgeon on Wed, May 14 2003 at 5:08PM PDT

Try this:

tell application "iTunes"
    rewind
end tell

Then update the original play/pause code:

tell application "iTunes"
	set theState to player state
	if theState is fast forwarding or theState is rewinding then
		resume
	else
		playpause
	end if
end tell

The same works for 'fast forward', also.

There's code in a previous comment on how to not launch iTunes if it's not currently running.

It's possible to use the same key for rewind/resume:

tell application "iTunes"
	set theState to player state
	if theState is playing then
		rewind
	else
		resume
	end if
end tell


[ Reply to This | # ]