# # Script to State which Mp3 is playing on OS X only.. # # Commands: # /mp3say - says (once) the current song that is playing... # /mp3announce - states the current song playing whenever the song changes... # typing /mp3announce again will stop the mp3 announce timer. $MP3SCRIPTDATA = ' tell application "iTunes" set _title to name of current track set _artist to artist of current track return {_artist, " - ", _title} as string end tell '; sub getmp3 { local('$mp3handle $mp3script $mp3song'); # fancy code for obtaining the location and proper path format for mp3say.apl $mp3script = getFileProper(getScriptPath("mp3say.irc"), "mp3say.apl"); if (!-exists $mp3script) # if the iTunes apple script doesn't exist, create it... { $mp3handle = openf('>' . $mp3script); println($mp3handle, $MP3SCRIPTDATA); closef($mp3handle); } $mp3handle = exec("osascript $mp3script"); if (!-eof $mp3handle) { $mp3song = readln($mp3handle); } closef($mp3handle); return $mp3song; } alias mp3say { say("I'm listening to: \b" . getmp3()); } alias mp3announce { if ($1 eq "stop" || $mp3timer ne $null) { stopTimer($mp3timer); $mp3timer = $null; echo("*** Stopped mp3 announcements"); } else { $mp3timer = addTimer(&mp3check, 10 * 1000); mp3check(); } } sub mp3check { local('$mp3check'); $mp3check = getmp3(); if ($mp3check ne $CURRENT_MP3 && $mp3check ne $null && $mp3check ne "EOF") { $CURRENT_MP3 = $mp3check; call("/ame is now listening to:\b $CURRENT_MP3"); } }