Reputation: 1017
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
Upvotes: 2
Views: 1724
Reputation: 10238
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()
.
Upvotes: 0
Reputation: 7846
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!
Upvotes: 4