tags:

views:

71

answers:

2

Hi, I'd like to get the name of the song that iTunes is currently playing. What API should I refer to?

I'd like to use that both for a dashboard widget or a Java/python application depending on what it is easier to use.

Do you have some references for me?

Thanks in advance, Mario

+2  A: 

Here's an AppleScript that will tell you the information of the currently playing song in iTunes -

on run
  set info to ""
  tell application "System Events"
    set num to count (every process whose name is "iTunes")
  end tell
  if num > 0 then
    tell application "iTunes"
      if player state is playing then
        set trackname to name of current track
      end if
    end tell
  end if
  return trackname
end run

I hope that helps you in some way!

Raphael Caixeta
Is it possible to get informed about the change song event or do I have to do polling in order to recognize that the song has changed?
mariosangiorgio
A: 

I'm assuming you're developing for OS X based on the Dashboard widget remark. In that case, the easiest way to interface with iTunes from a Dashboard widget, Python, or Java would be calling AppleScript (see Raphael's code) through an AppleScript library. For Python, appscript. For Java, the com.apple.cocoa package. And I believe Dashboard widgets can do it by calling the oascript command line tool and widget.system().

Hao Lian
How can I tell Eclipse where to find the com.apple.cocoa package?
mariosangiorgio
http://lists.apple.com/archives/java-dev/2003/Jul/msg00118.html
Hao Lian