![]() |
Now to recapture my hijacked thread and post my solution.
I took the "grep -v grep" off of the set "cmdOutput to do shell script "ps ax | grep server-bin"" line so that I would get both the grep of the grep and the grep of the server-bin thereby eliminating the NULL condition. Code:
24931 p1 R+ 27:40.28 ./server-bin global sfcsar.aaoMy final script is this: Code:
on idleCiao, and thanks again atFault |
Just a helpfull pointer...
ps -axc to take out the path name of the application for example: Code:
[:~] jkenney% ps -ax | grep init |
Thought I would dust this thread off and post my solution in case it is helpful to anyone else.
Code:
set isRunningComskip to do shell script "ps ax | grep comskip.exe | grep -v grep | wc -l | cut -d ' ' -f8"B |
As jkenney pointed out (though perhaps not emphatically enough),
using the 'c' option with ps not only trims off the pathname... but, ALSO totally obviates the need for the extra |grep -v grep ! If someone can explain *why* that actually works, I'm all ears. [seems like grep should still find the same string it did before?] -- Another trick -- which works without the 'c' option -- is to prefix a [/] bracket expression onto the searched name. So grep must then match a leading / forward slash, right before the string. Thus -- for example, to see if Safari is running -- this will do the trick: § Quote:
Yes... wc does stick a bunch of spaces in there, for some odd reason. But the shell sees spaces as nothing but separation: IFS=$' /t/n' So... it can still do math, and "if" comparisons, etc., just fine. For most purposes, simply don't quote the (integer) variable... and the spaces go away! E.g.: if [ $isRunningComskip -gt 0 ]all work fine. (the spaces are simply ignored/discarded) -HI- |
Quote:
Code:
% ps -ax | grep grep |
Quote:
Code:
set isRunningComskip to do shell script "ps ax | B |
Quote:
[i can see it does work... but not how/why it works.] Try this: $ ps -ax | grep Safari 88880 ?? 0:39.45 /Applications/Safari.app/Contents/MacOS/Safari -psn_0_454767 94274 ttys000 0:00.00 grep Safari $ ps -acx | grep Safari 88880 ?? 0:39.45 Safari Now... why doesn't the 2nd grep *also* see itself (grepping Safari)? The text being matched is simply "Safari"... so, i don't get it. |
Quote:
However, most of the examples in this thread seem to use AppleScript only to either talk to the shell (do shell script) or Terminal (tell application "Terminal"). So --unless there's some use for it [not shown] -- a shell script should suffice. But yes, to have AppleScript display that number as text, we'd need to strip the spaces (if we cared about it looking perfect). I much prefer sed over cut: Code:
|
Quote:
The output from the 'ps -axc' case shows that the line in the output from the 'ps' command with those options is simply "19541 ttys000 0:00.00 grep" - there is no "grep grep" in the 'ps' output. Similarly when you 'grep Safari', there is no "Safari" in the line from 'ps' for that process since the "-c" option does not include the command's arguments in the output. Or here's another way to understand: Run a shell script that loops, running a command like 'grep foo /etc/passwd' and then look at the full output from 'ps -xc' with something like: ps -axc | more |
Quote:
*NOW* I get it. [duh :o ] Thanks C.H. |
Quote:
B |
| All times are GMT -5. The time now is 10:21 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.