Wednesday, September 17, 2014

#1 2012-01-31 03:35:08 am

MaaliRuisku
Member
Registered: 2012-01-30
Posts: 8

How can I find out if certain processes (multiple) are running?

I have found several posts regarding how you can find out if particular process is running.

How can I find out if multiple processes are running?

I want to check if couple of apps are running. If they aren't, I want to shut down the Mac.

Thanks!

Model: Mac Mini (Early 2009)
AppleScript: 2.3 (118)
Browser: Safari 535.7
Operating System: Mac OS X (10.6)


Filed under: running, multiple, processes

Offline

 

#2 2012-01-31 04:08:04 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 1906

Re: How can I find out if certain processes (multiple) are running?

Something like this?

Applescript:


set appNames to {"Finder", "httpd", "System Events", "Mail"}

set AppleScript's text item delimiters to "\\|"
set expression to appNames as string
set AppleScript's text item delimiters to ""

set runningApps to every paragraph of (do shell script "ps -acwx -o command | grep -i " & quoted form of expression & " || echo 'false'")

if runningApps is {"false"} then
   tell application "System Events" to shut down
end if

Last edited by DJ Bazzie Wazzie (2012-01-31 04:09:28 am)


Kind regards

Offline

 

#3 2012-01-31 04:21:03 am

MaaliRuisku
Member
Registered: 2012-01-30
Posts: 8

Re: How can I find out if certain processes (multiple) are running?

I have to give it a try when I get to the Mac!

One question though. I have to change {"Finder", "httpd", "System Events", "Mail"} to right app names, correct? In this case EyeTV and Turbo.264 HD.

Many thanks! smile

Last edited by MaaliRuisku (2012-01-31 04:21:35 am)

Offline

 

#4 2012-01-31 05:13:16 am

MaaliRuisku
Member
Registered: 2012-01-30
Posts: 8

Re: How can I find out if certain processes (multiple) are running?

I tried the script and put some own script too.

Applescript:

on run
   tell application "EyeTV"
       if is_recording is false then
           tell application "EyeTV" to quit
       end if
   end tell
   delay 15
   tell application "Turbo.264 HD"
       if isEncoding is false then
           tell Application "Turbo.264 HD" to quit
       end if
   end tell
   delay 15
   set appNames to {"EyeTV", "Turbo.264 HD"}
   
   set AppleScript's text item delimiters to "\\|"
   set expression to appNames as string
   set AppleScript's text item delimiters to ""
   
   set runningApps to every paragraph of (do shell script "ps -acwx -o command | grep -i " & quoted form of expression & " || echo 'false'")
   
   if runningApps is {"false"} then
       tell application "System Events" to shut down
   end if
end run

I get this kind of log:

Applescript:

tell application "EyeTV"
   get is_recording
       --> false
   quit
end tell
tell Application "Turbo.264 HD"
   get isEncoding
       --> true
end tell
tell current application
   do shell script "ps -acwx -o command | grep -i 'EyeTV\\|Turbo.264 HD' || echo 'false'"
       --> "EyeTV Helper
Turbo.264 HD"
end tell

Why is EyeTV Helper showing? I can't find the process from Activity Monitor.

Should this script work?

Offline

 

#5 2012-01-31 06:51:57 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 1906

Re: How can I find out if certain processes (multiple) are running?

MaaliRuisku wrote:

Applescript:

tell application "EyeTV"
   get is_recording
       --> false
   quit
end tell
tell Application "Turbo.264 HD"
   get isEncoding
       --> true
end tell
tell current application
   do shell script "ps -acwx -o command | grep -i 'EyeTV\\|Turbo.264 HD' || echo 'false'"
       --> "EyeTV Helper
Turbo.264 HD"
end tell

Why is EyeTV Helper showing? I can't find the process from Activity Monitor.

Should this script work?

It's because grep looks if the word fits in the the line instead of matching the whole line. When you give the x option as an argument for grep it will match the entire line and will result only that line that matches exactly.

And yes you should alter the list appNames to the processes you want to lookup. The list runningApps will show you the processes that are running from the appNames list. When none of processes in appNames is running it will return {"false"}.

Applescript:

set appNames to {"Finder", "httpd", "System Events", "Mail", "iTunes"}

set AppleScript's text item delimiters to "\\|"
set expression to appNames as string
set AppleScript's text item delimiters to ""

set runningApps to every paragraph of (do shell script "ps -acwx -o command | grep -ix " & quoted form of expression & " || echo 'false'")


Kind regards

Offline

 

#6 2012-02-01 07:59:24 am

MaaliRuisku
Member
Registered: 2012-01-30
Posts: 8

Re: How can I find out if certain processes (multiple) are running?

The script works perfectly. Thanks!

However I'm trying to accomplish another task.

I want to open all files from certain folder with Turbo.264 HD and start encoding.

I made this:

Applescript:

tell application "Turbo.264 HD"
open file "disk:folder"
encode

It's simple and it works but won't if folder is empty. If the folder is empty Turbo.264 HD says ".." was not added because it is in an unsupported format and then nothing happens.

I tried to add

Applescript:

delay 10
if isEncoding is false then
tell Application "Turbo.264 HD" to quit
else
       encode
   end if

but didn't help.

I also tried

Applescript:

tell application "System Events"
   keystroke return

but didn't help either.

Any ideas?

Last edited by MaaliRuisku (2012-02-01 08:00:51 am)

Offline

 

#7 2012-02-01 08:13:19 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 1906

Re: How can I find out if certain processes (multiple) are running?

The best way is to look if the folder is empty or not before you start encoding

Applescript:

set theFolder to "disk:folder"

set folderIsEmpty to count of (every paragraph of (do shell script "ls " & quoted form of POSIX path of theFolder)) = 0

if you want to check for a certain file extension you can use

Applescript:

set theFolder to "disk:folder" --don't end theFolder with ":"
set theExtension to "txt"

set folderIsEmpty to (count of (every paragraph of (do shell script "ls " & quoted form of POSIX path of theFolder & "/*." & theExtension & " || echo ''"))) = 0

So when folderIsEmpty is true then you won't start the encoding.

Last edited by DJ Bazzie Wazzie (2012-02-01 08:14:05 am)


Kind regards

Offline

 

#8 2012-02-01 11:07:01 am

MaaliRuisku
Member
Registered: 2012-01-30
Posts: 8

Re: How can I find out if certain processes (multiple) are running?

Thank you Sir! You are really my hero! smile

I have used the script just week or two, so it takes time to get used to! big_smile

Offline

 

#9 2012-02-01 02:03:42 pm

MaaliRuisku
Member
Registered: 2012-01-30
Posts: 8

Re: How can I find out if certain processes (multiple) are running?

Could you help me one more time?

I tried the same script to open files with Name Mangler and it worked beautifully.

I just need two additions.

1. The folder contains .ts and .mpg files. I just want to open .mpg.

2. Any idea how to remove files which have been edited x hours ago (outdated files)?

Thanks!

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.039 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)