unix processes

Hi,

I had a script that could get the current non-background processes, but lost it. It used unix ‘ps’ and was very efficient… I can’t remember the flags and read the man pages but it eludes me.

Thanks,
Kel.

Hmm… not sure here, the “best” output I could get from ps was this:


$ ps -cx
PID TT STAT TIME COMMAND
197 ?? Ss 1:42.74 WindowServer
208 ?? Ss 0:07.95 ATSServer
270 ?? Ss 0:01.27 loginwindow
370 ?? Ss 0:00.38 pbs
379 ?? S 0:01.55 Dock
380 ?? S 0:03.36 SystemUIServer
381 ?? S 0:04.56 Finder
400 ?? S 0:00.09 iTunesHelper
401 ?? S 0:01.49 SecureClient
405 ?? S 1:16.30 Mail
407 ?? S 3:00.93 Safari
597 ?? S 0:17.79 Terminal
725 ?? S 0:19.93 Script Editor
726 ?? S 0:00.97 System Events
599 std S 0:00.23 -bash
$

Obviously, this still includes some background processes. But what about some vanilla AppleScript? :slight_smile:


on getProcesses()
	tell application "System Events"
		set procs to get processes where visible = true
		set proclist to {}
		repeat with proc in procs
			set end of proclist to (name of proc)
		end repeat
	end tell
	return proclist
end getProcesses

Regards,
danB

Model: iBook g3/800 14"
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

We can eliminate the control loop if we wish:

tell application "System Events"
   set yourVariableHere to (name of every process whose visible = true)
end tell

It was something like that, but just the list of process names. Something like:

do shell script “ps -cx command”

and another flag to take out the column labels. I must have read the man pages about 10 times this time and still can’t get it.

I know how to do the AppleScript way, but the ps gets app processes that soemtimes aren’t listed.

Thanks a lot,

Think I got it. Sonething like this:

set ps_out to do shell script “ps -cxo command”
set ps_list to paragraphs 2 through -1 of ps_out

Now how to get rid of the system processes?

Hi kel. Have you considered something like this?

tell application "System Events" to name of processes whose background only is false