MACSCRPT Archives

July 2006

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
John Baxter <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Wed, 12 Jul 2006 11:24:49 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (53 lines)
On Jul 12, 2006, at 10:34 AM, Peter Boardman wrote:

> 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.

Or base the test on this quick tire kicking:

try
	do shell script "ps axuw | grep '[i]Tunes '"
	display dialog "It's running"
on error
	display dialog "It's not running"
end try

Notes:
1.  The [i] matches the "i" in iTunes, but the grep does not match  
the "iTunes" in the grep process (routine well-known Unix hack)
2.  The trailing space in the grep pattern is needed to avoid  
matching iTunesHelper, which seems to keep running after iTunes is quit.
3.  This version will tell you whether any user is running iTunes.   
Leaving out the "a" in "ps axuw" might tell you whether the user  
running the script is running iTunes (untested).
4.  The quoting of the grep pattern is needed both for the [i] part  
and for the trailing space.

My guess is that the do shell script form will use fewer resources  
than the others, which only matters if you plan to run it repeatedly  
and frequently (and doesn't matter at all when display dialog is  
involved, of course).

   --John

ATOM RSS1 RSS2