Version 0 of itunes music player

Updated 2005-10-24 07:09:35

Itunes is the music management software from Apple [L1 ]. It can be used to manage music files, podcasts, and now videos. On windows, there is also a COM interface. The documentation for this is available via the itunes sdk [L2 ], as well as samples in javascript.

The examples below really only make sense on Windows.


The setup: with geoshell [L3 ], hotkeys can be (fairly) easily created to do things like control the volume of the machine, mute, etc. These hotkeys are global hotkeys since they do not depend on any particular application to have focus. itunes for windows has some hotkeys to handle volume, pause, etc, but they are not global. I prefer to keep itunes minimised and peeking out from the system tray, so giving focus to itunes can be problematic at times. So, I wrote a series of tcl scripts to control itunes via COM.

First, pause/play. When run, this script will pause and unpause itunes. This is very sensitive to context, though: whatever item the cursor is on is what gets played.

  package require tcom

  set iTunes [::tcom::ref createobject "iTunes.Application"]

  $iTunes PlayPause

  exit

Simple enough. Next, I create a hotkey for geoshell. When pressing control+window+p, the following command gets executed

  "c:\tcl\bin\wish.exe" "C:\Documents and Settings\wl\batch\itunes_pause_play.tcl"

and all seems good.

To expand on this, I next create a pair of tcl scripts to control the volume

  package require tcom

  set interval -2
  set iTunes [::tcom::ref createobject "iTunes.Application"]

  set vol [$iTunes SoundVolume]

  if {[incr vol $interval] <= 0} {
      set vol 0
  }

  $iTunes SoundVolume $vol

  exit

and

  package require tcom

  set interval 2
  set iTunes [::tcom::ref createobject "iTunes.Application"]

  set vol [$iTunes SoundVolume]

  if {[incr vol $interval] >= 100} {
      set vol 100
  }

  $iTunes SoundVolume $vol

  exit

I create hotkeys for control+window+down to call the first script, and control+window+up to call the second script.