Welcome, guest | Sign In | My Account | Store | Cart

Simple TCL commands can control your iTunes player, add network control, or create an alternate interface. This recipe uses the tcom package on Windows.

Tcl, 133 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Control iTunes from TCL using TCOM package on Windows

# [http://www.vex.net/~cthuang/tcom/](http://www.vex.net/~cthuang/tcom/)
package require tcom

# start iTunes or take over existing iTunes application if already running
set i [::tcom::ref createobject "iTunes.Application"]

# get iTunes version
$i Version
	9.0.3.15

# set volume (0 to 100)
$i SoundVolume 75

# play the currently selected track
$i Play
$i Stop

$i Pause
$i Resume

$i PreviousTrack
$i NextTrack

# get current song play position (seconds)
$i PlayerPosition

# set song position (seconds)
$i PlayerPosition 96

# Track info
set track [$i CurrentTrack]
$track Name
$track Album
$track Artist
$track Time
$track BPM
$track Year
$track Comment
$track Kind
$track KindAsString

# Example track:
foreach t {Artist Name Time Album Year BPM Comment KindAsString} {puts [format "%-12s: %s" $t [$track $t]]}
	Artist      : The Fixx
	Name        : Saved By Zero
	Time        : 3:26
	Album       : React
	Year        : 1987
	BPM         : 90
	Comment     : TCL rocks
	KindAsString: MPEG audio file


# GET ALL AVAILABLE ITUNES METHODS
set iid [::tcom::info interface $i]
$iid methods

# dump a sorted list of all itunes tcom calls
foreach m [lsort -index 2 -unique [$iid methods]] {puts [lindex $m 2]}
	AppCommandMessageProcessingEnabled
	Authorize
	BackTrack
	BrowserWindow
	CanSetShuffle
	CanSetSongRepeat
	CheckVersion
	ConvertFile
	ConvertFile2
	ConvertFiles
	ConvertFiles2
	ConvertOperationStatus
	ConvertTrack
	ConvertTrack2
	ConvertTracks
	ConvertTracks2
	CreateEQPreset
	CreateFolder
	CreateFolderInSource
	CreatePlaylist
	CreatePlaylistInSource
	CurrentEQPreset
	CurrentEncoder
	CurrentPlaylist
	CurrentStreamTitle
	CurrentStreamURL
	CurrentTrack
	CurrentVisual
	EQEnabled
	EQPresets
	EQWindow
	Encoders
	FastForward
	ForceToForegroundOnDialog
	FullScreenVisuals
	GetITObjectByID
	GetITObjectPersistentIDs
	GetPlayerButtonsState
	GotoMusicStoreHomePage
	ITObjectPersistentIDHigh
	ITObjectPersistentIDLow
	LibraryPlaylist
	LibrarySource
	LibraryXMLPath
	Mute
	NextTrack
	OpenURL
	Pause
	Play
	PlayFile
	PlayPause
	PlayerButtonClicked
	PlayerPosition
	PlayerState
	PreviousTrack
	Quit
	Resume
	Rewind
	SelectedTracks
	SetOptions
	SoundVolume
	SoundVolumeControlEnabled
	Sources
	Stop
	SubscribeToPodcast
	UpdateIPod
	UpdatePodcastFeeds
	Version
	VisualSize
	Visuals
	VisualsEnabled
	Windows

Tested with TCL 8.6.0b on Windows 7 with tcom 3.9 and iTunes 9. This recipe needs examples for playlists, album artwork, and UI elements.

Created by Frank Bannon on Tue, 30 Mar 2010 (MIT)
Tcl recipes (162)
Frank Bannon's recipes (3)

Required Modules

Other Information and Tasks