How to find out if an application is running

2005-10-12 Thread Ted Zeng
Hi,

I would like to find out if an application like Illustrator is running
On OS X or not from a perl script. How can I do it?

ps doesn't list the processes like Illustrator.

Ted Zeng
Adobe Systems



Re: How to find out if an application is running

2005-10-12 Thread Jeff Lowrey
I'd think with your email address, you should know which process 
Illustrator runs as, or at least be able to find out... ;-)


Use AppleScript, from osascript or from Mac::Glue or etc.

You won't find a single, cross platform method for answering this 
question.  Ergo, if you need the same piece of code to run on 
multiple OSes, you will need to code to detect which platform it's 
running on, and then DTRT on that platform.


-Jeff Lowrey

At 05:37 PM 10/12/2005, Ted Zeng wrote:

Hi,

I would like to find out if an application like Illustrator is running
On OS X or not from a perl script. How can I do it?

ps doesn't list the processes like Illustrator.

Ted Zeng
Adobe Systems




Re: How to find out if an application is running

2005-10-12 Thread John Delacour

At 2:37 pm -0700 12/10/05, Ted Zeng wrote:


I would like to find out if an application like Illustrator is running
On OS X or not from a perl script. How can I do it?



#!/usr/bin/perl
@processes = split /, /, `osascript -e '
tell app system events to name of processes whose visible is true'`;
print join $/, @processes


...if you don't mind waiting a little.

JD



Re: How to find out if an application is running

2005-10-12 Thread Sherm Pendley

On Oct 12, 2005, at 5:37 PM, Ted Zeng wrote:


I would like to find out if an application like Illustrator is running
On OS X or not from a perl script. How can I do it?

ps doesn't list the processes like Illustrator.


px x does. ;-)

#!/usr/bin/perl

use strict;
use warnings;

my $ps = (grep /Adobe Illustrator/, split(\n, `ps x`))[0];
my ($pid, $tt, $status, $time, $cmd) = split( , $ps, 5);

print EOF;
PID = $pid
 TT = $tt
 STATUS = $status
   TIME = $time
CMD = $cmd
EOF

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org



Re: How to find out if an application is running

2005-10-12 Thread Chris Nandor
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Ted Zeng) wrote:

 ps doesn't list the processes like Illustrator.

Yeah, like Sherm said.

These are the two most common methods that I've used, along with a sort-of
port of JD's AppleScript to Mac::Glue.

   #!perl -wl
   # simple
   print 1 if grep 'Photoshop', `ps auxw`;

   # heh
   use Mac::Glue ':all';
   my $syse = new Mac::Glue 'System Events';
   print 1 if $syse-obj(processes = whose(
  creator_type = contains = '8BIM'  # can't see way to do bundle ID?
   ))-get;

   # my favorite
   use Mac::Apps::Launch;
   print IsRunning('com.adobe.photoshop');

The latter is almost surely your best solution.  No calls to external apps, 
is included with Tiger, and doesn't rely on possibly conflicting paths and 
app names.

It uses Mac::Processes to loop over running applications, and is probably as 
efficient in that regard as the other methods, since they all basically have 
to do the same thing too.  But that it doesn't have to call out to another 
app makes it that much more efficient.

It can also accept a four-char code, in this case, IsRunning('8BIM'), like 
the Mac::Glue code does.

For the Mac::Apps::Launch code to work, you need version 1.90; 1.91 is 
included in Tiger, so you should be fine if you're using that.  Older 
versions of the module can still handle the four-char code syntax.

-- 
Chris Nandor  [EMAIL PROTECTED]http://pudge.net/
Open Source Technology Group   [EMAIL PROTECTED] http://ostg.com/


Re: How to find out if an application is running

2005-10-12 Thread Chris Nandor
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Chris Nandor) wrote:

Oops, typo.  This:

print 1 if grep 'Photoshop', `ps auxw`;

should be:

print 1 if grep /Photoshop/, `ps auxw`;



And I forgot to mention -- just because it may be useful -- you can also 
convert between PID and PSN.  Also in Mac::Processes, there are 
GetProcessPID() and GetProcessForPID().  The former converts a PSN to a PID, 
and the latter a PID to a PSN.

Much of the Mac:: API can accomodate either if necessary (Mac::Glue can 
target by PSN or PID, and a process object from System Events can give you 
a PSN or PID), but if you need to convert from one or the other, you can use 
this API.

One example I like:

   use Mac::Processes;
   while (my($psn, $psi) = each %Process) {
  kill 15, GetProcessPID($psn) if $psi-processName =~ /Photoshop/i;
   }

-- 
Chris Nandor  [EMAIL PROTECTED]http://pudge.net/
Open Source Technology Group   [EMAIL PROTECTED] http://ostg.com/


Re: How to find out if an application is running

2005-10-12 Thread Sherm Pendley

On Oct 12, 2005, at 7:47 PM, Ted Zeng wrote:


BTW, Apple just reported yesterday that Mac units shipped increased
By 48% last quarter. Sound like Mac is gaining market share.


Yeah - and AAPL immediately dropped 10%. I'll *never* understand Wall  
Street.


sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org



Re: How to find out if an application is running

2005-10-12 Thread Joel Rees


On 平成 17/10/13, at 9:06, Sherm Pendley wrote:


On Oct 12, 2005, at 7:47 PM, Ted Zeng wrote:



BTW, Apple just reported yesterday that Mac units shipped increased
By 48% last quarter. Sound like Mac is gaining market share.



Yeah - and AAPL immediately dropped 10%. I'll *never* understand  
Wall Street.


People who make money out of money have strange superstitions. Good  
news is bad news. (Or, if you want to play with conspiracy  
theories, ... )


I suspect what's happening is that the expected drop before the shift  
to intel is not happening. Rather than seeing the steady sales as a  
confirmation of Mac OS X, they are worried that Steve might decide to  
keep both CPU lines, messing up their misguided plans to capitalize  
on the next big monopoly.


(My delusions, of course, do not necessarily reflect the views of my  
employer.)


Joel Rees   [EMAIL PROTECTED]
digitcom, inc.   株式会社デジコム
Kobe, Japan   +81-78-672-8800
** http://www.ddcom.co.jp **