Check if Terminal process is active?

I’m writing a GUI shell for a command line tool. The app will open the terminal and send the request to the terminal and process it. I’ve gotten everything to work so far, however, I’d like to have a modal dialog appear when the terminal is processing the last request sent so the app can’t send any more requests until the current process stops. The modal window will have just a spinning progress bar and something like “currently processing. please wait…” then when the terminal process is complete, the modal window will close.

Is this possible? And if so…any leads or pointers?

TIA

OK…since I posted this, I now see that when my process is running, it’s name is in the process list in the activitiy monitor. So I’m guessing that I will have to continuously keep checking to see if the process is active using something like this…


if (list processes) contains "MyApp" then 
   -- keep window open
else
   -- close window
end if

But I’d need to put it in a loop somehow, but I don’t know where…
If this I’m getting close here, please let me know…

Another update…I have this now…

set testPanel to window "test"
display testPanel attached to window "Main"
					
set targetApp to "myCommandLineUtility"
set loopCount to 0
delay 2
repeat until loopCount > 0
	tell application "System Events"
		set processExists to exists process targetApp
	end tell
						
	if processExists is false then
		set loopCount to 1
		close panel testPanel
	end if
end repeat

Now…this works and it doesn’t work…it works if I set the targetApp to “Terminal”…then when I manually quit the Terminal…the panel will close…but if I set the targetApp to “theCommandLineTool”…it doesn’t work…is it because it’s a process running under the Terminal?

Any ideas?

Could you use something like this to determine if a shell process is listed via the “ps” command?

http://scriptbuilders.net

[This script was automatically tagged for color coded syntax by Script to Markup Code]

i have NO IDEA what that means, but it works perfect!!!
Thanks a bunch!

The “do shell script” is using ‘ps’ with c a x flags to trim the output of the ‘ps’ command to five fields, then ‘awk’ displays the fifth field of the output e.g.,


385  ??   S      0:09.05    Dock
  f1   f2   f3         f4            f5
-->Dock

Perhaps a better way to tackle this problem is to use the Process ID number (as that handles the case where there might be two concurrent processes running with the same name). The do shell script technote (TN2065) describes how to fetch the number (from your original do shell script call) using an echo $!:

set thePID to do shell script "my_command > /dev/null 2>&1 & echo $!"

To test, you can simply use:
return ((count of paragraphs in (do shell script "ps -p " & thePID)) > 1)

Which returns true if the process is still running, or false if it isn’t. Of course you’ll probably replace the return statement with an if statement of some kind. :rolleyes: Duh!

Note: the ps -p PID command will return a single line (the header) if there are no processes associated with the given PID, otherwise it will return two lines, if there is, hence the test for greater than one paragraph.