Getting the file path of a currently playing iTunes track with Applescript
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.
tell application "iTunes"
if running then
set state to player state
if state = playing then
set trackProperties to (properties of current track)
set theArtist to artist in trackProperties
set theTitle to name in trackProperties
set theAlbum to album in trackProperties
set theTime to time of trackProperties
set theGrouping to grouping in trackProperties
set theGenre to genre in trackProperties
set theKind to kind in trackProperties
set theYear to year of trackProperties
set theComments to comment in trackProperties
set playCount to played count in trackProperties
set theTrack to track number in trackProperties
set numTracks to track count in trackProperties
set theDisc to disc number in trackProperties
set numDiscs to disc count in trackProperties
set bitRate to bit rate in trackProperties
try
set thePath to POSIX path of (get location of current track)
on error
set thePath to "Not playing from local library."
end try
else
set state to "none"
end if
else
set state to "none"
end if
end tell