I've got an Applescript program that works really well for getting most of the info of a currently playing track into a series of named variables:
tell application "System Events"
if application process "iTunes" exists then
tell application "iTunes"
set state to player state
if state = playing
tell current track
set theArtist to artist
set theTitle to name
set theAlbum to album
set theTime to time
set theGrouping to grouping
set theGenre to genre
set theKind to kind
set theYear to year
set theComments to comment
set playCount to played count
set theTrack to track number
set numTracks to track count
set theDisc to disc number
set numDiscs to disc count
set bitRate to bit rate
end tell
else
set state to "none"
end if
end tell
else
set state to "none"
end if
end tell
But I'm completely baffled on how to get actual file path of the current track. The Applescript library for iTunes has a "file track" entry that has a "location" item, but I haven't been able to figure out how to use it in this context. Any help would be greatly appreciated.
Best Answer
You don't need System Events, iTunes can tell if it's running or not.
Also, set the properties of
current track
to a variable and then get the info from the variable. The reason for this is you make only one lower level call(properties of current track)
and then the assigning of the other variables gets the info from a variable containing all the info, and not making 15 separate lower level calls to get the info, This should be faster and more efficient code.