Re: How to find out if an application is running

2005-10-25 Thread James Reynolds

At 1:22 PM -0700 10/14/05, Chris Nandor wrote:

I just uploaded Mac::Apps::Launch.  Now IsRunning() returns the PSN, instead
of simple true/false (1/0).

Here's a fun, simple, and efficient script to kill the Dock (which should
relaunch immediately):

   use Mac::Apps::Launch 1.92;
   use Mac::Processes;
   use POSIX 'SIGTERM';

   my $psn = IsRunning('com.apple.dock');
   kill SIGTERM, GetProcessPID($psn);


Don't try that with Launch 1.91!

--

Thanks,

James Reynolds
University of Utah
Student Computing Labs
[EMAIL PROTECTED]
801-585-9811


Re: How to find out if an application is running

2005-10-25 Thread Joseph Alotta

why not?

On Oct 25, 2005, at 6:13 PM, James Reynolds wrote:


At 1:22 PM -0700 10/14/05, Chris Nandor wrote:

I just uploaded Mac::Apps::Launch.  Now IsRunning() returns the  
PSN, instead

of simple true/false (1/0).

Here's a fun, simple, and efficient script to kill the Dock (which  
should

relaunch immediately):

   use Mac::Apps::Launch 1.92;
   use Mac::Processes;
   use POSIX 'SIGTERM';

   my $psn = IsRunning('com.apple.dock');
   kill SIGTERM, GetProcessPID($psn);



Don't try that with Launch 1.91!

--

Thanks,

James Reynolds
University of Utah
Student Computing Labs
[EMAIL PROTECTED]
801-585-9811





Re: How to find out if an application is running

2005-10-25 Thread James Reynolds

Sorry...

It killed everything running as me.  I was dumb enough to try it on 
my main computer.


James

At 6:16 PM -0500 10/25/05, Joseph Alotta wrote:

why not?

On Oct 25, 2005, at 6:13 PM, James Reynolds wrote:


At 1:22 PM -0700 10/14/05, Chris Nandor wrote:


I just uploaded Mac::Apps::Launch.  Now IsRunning() returns the PSN, instead
of simple true/false (1/0).

Here's a fun, simple, and efficient script to kill the Dock (which should
relaunch immediately):

   use Mac::Apps::Launch 1.92;
   use Mac::Processes;
   use POSIX 'SIGTERM';

   my $psn = IsRunning('com.apple.dock');
   kill SIGTERM, GetProcessPID($psn);



Don't try that with Launch 1.91!

--

Thanks,

James Reynolds
University of Utah
Student Computing Labs
[EMAIL PROTECTED]
801-585-9811




Re: How to find out if an application is running

2005-10-14 Thread Dominic Dunlop

On 2005–10–13, at 19:36, Ted Zeng wrote:

As it turns out, only Sherm's version works
For all the situations.


Great! Go for it.

The tough bit about there being more than one way to do it is to  
resist the temptation to try them all, even after you've found one  
that works. I can't always resist the temptation...

--
Dominic Dunlop



Re: How to find out if an application is running

2005-10-14 Thread Peter N Lewis

At 20:02 -0700 13/10/05, Ted Zeng wrote:

Here is the fun part: I made a killapp.pl script and
Call it to kill Bridge with
`killapp.pl Bridge `

And it kills itself.

As it turned out, the script finds itself from the list because the
Command line includes Bridge(or Adobe Illustrator for Illustrator).


The standard trick for this, if the search is a regular expression, 
is to surround one of the letters with [], ie:


killapp.pl '[B]ridge'


It works. But somebody probably laughs at it.


It's hardly the first time, indeed the general find this application of

ps auxw | grep 

inevitably finds the search command unless you use a trick like the above, or:

ps auxw | grep  | grep -v grep

Enjoy,
   Peter.

--
http://www.stairways.com/  http://download.stairways.com/


Re: How to find out if an application is running

2005-10-14 Thread Ted Zeng
I like these solution.

Thanks.

ted

On 10/13/05 10:59 PM, Peter N Lewis [EMAIL PROTECTED] wrote:

 At 20:02 -0700 13/10/05, Ted Zeng wrote:
 Here is the fun part: I made a killapp.pl script and
 Call it to kill Bridge with
 `killapp.pl Bridge `
 
 And it kills itself.
 
 As it turned out, the script finds itself from the list because the
 Command line includes Bridge(or Adobe Illustrator for Illustrator).
 
 The standard trick for this, if the search is a regular expression,
 is to surround one of the letters with [], ie:
 
 killapp.pl '[B]ridge'
 
 It works. But somebody probably laughs at it.
 
 It's hardly the first time, indeed the general find this application of
 
 ps auxw | grep 
 
 inevitably finds the search command unless you use a trick like the above, or:
 
 ps auxw | grep  | grep -v grep
 
 Enjoy,
 Peter.



Re: How to find out if an application is running

2005-10-14 Thread Chris Nandor
I just uploaded Mac::Apps::Launch.  Now IsRunning() returns the PSN, instead
of simple true/false (1/0).

Here's a fun, simple, and efficient script to kill the Dock (which should 
relaunch immediately):

   use Mac::Apps::Launch 1.92;
   use Mac::Processes;
   use POSIX 'SIGTERM';

   my $psn = IsRunning('com.apple.dock');
   kill SIGTERM, GetProcessPID($psn);

-- 
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-13 Thread Dominic Dunlop

On 2005–10–12, at 23:37, 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.


A late arrival which hasn't been mentioned so far:

$ killall -0 Illustrator 2/dev/null  echo Illustrator is running

Broadly, killall sends a signal to any process with a name matching  
its final command-line parameter. (See the man page for chapter and  
verse.) Here we're sending signal zero instead of the default  
SIGKILL. Signal zero isn't really a signal at all: it acts as a  
could I send a signal if I wanted to? query. If a signal could be  
sent -- that is, if Illustrator is running -- killall exits with  
status zero (success), so the next command in the pipeline gets run;  
otherwise with one (failure), terminating the pipeline. The 2/dev/ 
null junks killall's diagnostic in the event that Illustrator isn't  
running.

--
Dominic Dunlop



Re: How to find out if an application is running

2005-10-13 Thread David Cantrell
On Thu, Oct 13, 2005 at 08:51:22AM +0200, Dominic Dunlop wrote:
 A late arrival which hasn't been mentioned so far:
 $ killall -0 Illustrator 2/dev/null  echo Illustrator is running

killall is a Really Bad Idea.  While it does indeed do what you intend
on OS X, on other commercial Unices like Solaris it really does kill
all.  That is, it sends your chosen signal to all processes.  Not good.
So don't get in to the habit of using it.

-- 
David Cantrell | Benevolent Dictator Of The World

Eye have a spelling chequer / It came with my pea sea
It planely marques four my revue / Miss Steaks eye kin knot sea.
Eye strike a quay and type a word / And weight for it to say
Weather eye am wrong oar write / It shows me strait a weigh.


Re: How to find out if an application is running

2005-10-13 Thread Dominic Dunlop

On 2005–10–13, at 12:40, David Cantrell wrote:


On Thu, Oct 13, 2005 at 08:51:22AM +0200, Dominic Dunlop wrote:


A late arrival which hasn't been mentioned so far:
$ killall -0 Illustrator 2/dev/null  echo Illustrator is running



killall is a Really Bad Idea.  While it does indeed do what you intend
on OS X, on other commercial Unices like Solaris it really does kill
all.  That is, it sends your chosen signal to all processes.  Not  
good.

So don't get in to the habit of using it.


Aw, cut me some slack. This was specifically a Mac OS X query  
(Illustrator not being available on Solaris); the Solaris command  
only does its dangerous stuff for root (according to the man page --  
I don't have access to a Sun box); and Sun puts it in a place that  
shouldn't be on a normal user's PATH. Plus killall, BSD-style, is a  
neat command. Works on Linux too. But anyway. Here's Yet Another Way  
To Do It:


#!/usr/bin/perl -wl

use Proc::ProcessTable;
my $t = new Proc::ProcessTable;
for (@{$t-table}) {
  if ($_-cmndline =~  m%/Mail.app/%) { # *** Your app name here ***
print $_-pid;
last;
  }
}

Proc::ProcessTable is available from CPAN, and builds and runs  
without problem on Mac OS X. It also works in a lot of other  
environments (including Windows) (and Solaris).


Sadly, this approach no good for use from an optionally installed  
package, as you can't rely on the module being present. (Unless you  
were to include it as part of the bundle and tell perl how to find  
it, which would probably be more trouble than it's worth.)

--
Dominic Dunlop



Re: How to find out if an application is running

2005-10-13 Thread Ted Zeng
As it turns out, only Sherm's version works
For all the situations.

Here is what I did:
I clicked the menu File:New and Illustrator presents
An New document dialog.

Now, I go to execute the commands to kill it.

The AppleScript version could not kill it.
kill does kill it.(Sherm's code)

Killall doesn't seem to do anything even in the normal sitution
(I use Adobe Illustrator instead of Illustrator, otherwise it will
complaint there is no matching process)

I haven't tried Chris's version yet.

Ted zeng

On 10/13/05 7:55 AM, Dominic Dunlop [EMAIL PROTECTED] wrote:

 On 2005­10­13, at 12:40, David Cantrell wrote:
 
 On Thu, Oct 13, 2005 at 08:51:22AM +0200, Dominic Dunlop wrote:
 
 A late arrival which hasn't been mentioned so far:
 $ killall -0 Illustrator 2/dev/null  echo Illustrator is running
 
 
 killall is a Really Bad Idea.  While it does indeed do what you intend
 on OS X, on other commercial Unices like Solaris it really does kill
 all.  That is, it sends your chosen signal to all processes.  Not
 good.
 So don't get in to the habit of using it.
 
 Aw, cut me some slack. This was specifically a Mac OS X query
 (Illustrator not being available on Solaris); the Solaris command
 only does its dangerous stuff for root (according to the man page --
 I don't have access to a Sun box); and Sun puts it in a place that
 shouldn't be on a normal user's PATH. Plus killall, BSD-style, is a
 neat command. Works on Linux too. But anyway. Here's Yet Another Way
 To Do It:
 
 #!/usr/bin/perl -wl
 
 use Proc::ProcessTable;
 my $t = new Proc::ProcessTable;
 for (@{$t-table}) {
if ($_-cmndline =~  m%/Mail.app/%) { # *** Your app name here ***
  print $_-pid;
  last;
}
 }
 
 Proc::ProcessTable is available from CPAN, and builds and runs
 without problem on Mac OS X. It also works in a lot of other
 environments (including Windows) (and Solaris).
 
 Sadly, this approach no good for use from an optionally installed
 package, as you can't rely on the module being present. (Unless you
 were to include it as part of the bundle and tell perl how to find
 it, which would probably be more trouble than it's worth.)



Re: How to find out if an application is running

2005-10-13 Thread Jeff Lowrey

At 01:36 PM 10/13/2005, Ted Zeng wrote:

As it turns out, only Sherm's version works
For all the situations.


Actually, merely for the situation that you didn't tell us you were aiming for.

You asked How to find out if an application is running.

You didn't ask How do I find out a PID so I can kill a process.

-jeff 



Re: How to find out if an application is running

2005-10-13 Thread Ted Zeng
You are right.

After I got the info. On how to detect the process,
I added the codes to kill them. Then I thought they all work.
Didn't think what I had asked.

Here is the fun part: I made a killapp.pl script and
Call it to kill Bridge with
`killapp.pl Bridge `

And it kills itself.

As it turned out, the script finds itself from the list because the
Command line includes Bridge(or Adobe Illustrator for Illustrator).

Now, I put the app. Name in two part,
`killapp.pl Brid   ge`
And merge them in the killapp.pl script.

It works. But somebody probably laughs at it.

Ted zeng



On 10/13/05 4:05 PM, Jeff Lowrey [EMAIL PROTECTED] wrote:

 At 01:36 PM 10/13/2005, Ted Zeng wrote:
 As it turns out, only Sherm's version works
 For all the situations.
 
 Actually, merely for the situation that you didn't tell us you were aiming
 for.
 
 You asked How to find out if an application is running.
 
 You didn't ask How do I find out a PID so I can kill a process.
 
 -jeff 
 



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