
Control iTunes Under Windows #83
Chapter 11, Native Integration and Packaging
|
421
HACK
} catch (IOException ex) {
System.out.println("exception : " + ex.getMessage( ));
ex.printStackTrace( );
}
}
The line:
tell app "iTunes" to artist of current track as string
will call the artist method on the current track. It will return the artist as a
string and print it to standard out. You can get the standard output by
reading from
proc.getInputStream( )
. The code then prints the string as a
single line, so you can easily read it with the
readLine( ) method on a
DataInputStream
. Once you have the string back, you can print it, put it in a
JLabel, or do whatever else is appropriate for your program.
Apple has more information available on the iTunes AppleScript API at http://
www.apple.com/applescript/itunes/. With this API, you can do almost any-
thing. For example, you can get the name of a playing song:
tell app "iTunes" to name of current track as string
You can also get the album name:
tell app "iTunes" to album of current track as string
Muting the volume is also a piece of cake:
tell application "iTunes" to set mute to true
In the same vein, you can obtain the current volume:
tell application "iTunes" to sound volume as integer
Take a look at the API and see what other interesting things you can do.
Many of the other programs that come with Mac OS X can be controlled
with Apple Events as well, so there