On 2006-07-12, at 18:16, Mark Lively wrote:

> On Jul 12, 2006, at 1:00 PM, Peter Boardman wrote:
>
>> 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?
>>
> It is because when OSAScript compiles the script it needs to launch  
> iTunes.
>
> try this
>
> echo `osascript -e 'tell application "System Events"
> if (exists process "iTunes") then run script "tell application  
> \"iTunes\" to if player state is playing then get name of current  
> track"
> end tell'`

Brilliant - thanks. I hadn't thought about the compilation stage.