Remote control iTunes like a console CD player

Oct 16, '03 05:57:00PM

Contributed by: Hes Nikke

I have a KeySpan DMR and a JVC Remote for various uses. Among other things, I use it to control iTunes from any app that it isn't set up for it (i.e. most apps).

Read the rest of the hint for the basic how-to...

[robg adds: Some knowledge of AppleScript is required, as this hint provides the scripts but little in the way of instruction on implementing them with the KeySpan DMR. Still, if you've got one, this should help you get started with customization ... and my apologies to HesNikke, as this one sat in the queue for a longggg time!]


Panther proven!

I have my 1-5 keys bound to a variation of this AppleScript:


-- enter the number of stars you want to rate the current song :
property userRating : 5 
tell application "iTunes"
 set currVolume to sound volume
 if currVolume > 50 then
  set sound volume to currVolume / 3
 else
  set sound volume to currVolume / 2
 end if
 say "now setting " & name of current track & ¬
 " to  a rating of " & userRating  & " stars."
 set the rating of the current track to userRating * 20
 set sound volume to currVolume
end tell
And to make things complete, I also have the following buttons so that I can listen to my music in bed or while I sleep:

Stop:

tell application "iTunes"
 try
  set thename to (name of current track)
  set theartist to (artist of current track)
  if theartist = "" then
  else
   set theartist to ", by " & theartist
  end if
  on error
   set thename to ""
 end try
     
 if thename is not "" then
  set currVolume to sound volume
  if currVolume > 50 then
   set sound volume to currVolume / 3
  else
   set sound volume to currVolume / 2
  end if
  say "This is " & thename & theartist
  set sound volume to currVolume
 end if
end tell
Pause: (bonus!)

tell application "iTunes"
 set theRating to (rating of the current track) / 20
 set currVolume to sound volume
 if currVolume > 50 then
  set sound volume to currVolume / 3
 else
  set sound volume to currVolume / 2
 end if
 if theRating = 1 then
  say "this is " & name of current track & ¬
  ", and you rated it " & theRating & " star."
 else if theRating = 0 then
  say "this is " & name of current track & ¬
  ", and you haven't rated it"
 else
  say "this is " & name of current track & ¬
  ", and you rated it " & theRating & " stars."
 end if
 set sound volume to currVolume
end tell
Channel up: (the DMR ignores the volume buttons...)

tell application "iTunes"
 set currVolume to sound volume
 set newVolume to currVolume + 5
 set sound volume to newVolume
end tell
Channel down:

tell application "iTunes"
 set currVolume to sound volume
 if currVolume <e; 14 then -- we don't want it to be TOOO quiet :)
  set newVolume to currVolume - 5
 else
  set newVolume to 10
 end if
 set sound volume to newVolume
end tell
And finally, my simple ones...

Play:

tell application "iTunes"
 playpause
end tell
Fast forward:

tell application "iTunes"
 next track
end tell
Rewind:

tell application "iTunes"
 previous track
end tell

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030816015059261