Check if a process is running or not (Activity Monitor)

Hi,

I’m trying to figure out a script to search in the app Activity Monitor to see wether or not a process is running.

It works fine with the app names in the list of running processes, but when I try for example to see if “https://itunes.apple.com” is running it reports back as False, even though its running among the rest in the list…

https://itunes.apple.com” should be a simple process like the rest of the apps processes ?

This is the code Im using.

on is_running(appName)
	tell application "System Events" to (name of processes) contains appName
end is_running

set safRunning to is_running("https://itunes.apple.com")
return safRunning
if false then
	tell application "Safari"
	end tell
end if

Browser: Safari 602.3.12
Operating System: Mac OS X (10.10)

Hi,

System Events lists only application processes (.app)

Thanks, is there another application that can be used instead ? (that lists all processes)

Niklas

The shell command ps can list all processes

The problem is that System Events process listing is very limited. If the process you want to check is an application that is launched by you or on your behalve System Events is safe to check for running processes. Other processes cannot be listed and not be checked by system events.

The second thing is the false process name activity monitor will list. There is no process with the name http://itunes.apple.com. However there is an XPC service spawned by Safari to manage web content in your browser. The actual process name is probably com.apple.WebKit.WebContent. Having multiple windows or tabs open is hard to tell which process belongs to which content so therefore activity monitor will list the URL.

Here is a line I use in my script to find the Process ID of a running process.

set pid to do shell script "ps -ecwwo pid,comm | grep HandBrakeCLI"

This will set the variable pid to the process ID of “HandBrakeCLI” which is a process I was looking for.

Hope this helps