This AppleScript tests to see if iTunes is running before getting the
track name:
tell application "System Events"
if (exists process "iTunes") then tell application "iTunes" to if
player state is playing then get name of current track
end tell
returns
tell application "System Events"
exists process "iTunes"
false
end tell
if iTunes isn't running. But the same script wrapped inside osascript
always launches iTunes:
print `osascript -e 'tell application "System Events"
if (exists process "iTunes") then tell application "iTunes" to if
player state is playing then get name of current track
end tell'`
Why should this be? And is there a way of doing it?