how to make sure a certain program is running

Posted on
Fri Sep 06, 2013 1:06 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

how to make sure a certain program is running

how do I use indigo to make sure that a certain .app is running in the background, and if not start it (i know that one)

thx

Karl

Posted on
Fri Sep 06, 2013 10:19 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: how to make sure a certain program is running

figured it out:

put attached applescript into schedule ie every 5 minutes to check if compiled (export as app, keep active) applescript xxxxx.app is running.

Code: Select all
set pgmToFind to "xxxxx"
set theResponse to " "
try
   set theResponse to do shell script "ps aux | grep '" & pgmToFind & "' | awk '{print $2}' "
end try
-- if xxxxx is running then theResponse has 3 lines with 1 PID from :     ps, xxxx itself and one more --- have not figured out which one..
set noOfWords to count words of theResponse
if noOfWords < 3 then  -- if not running start script:
   do shell script "open '/Library/Application Support/Perceptive Automation/Indigo 6/Scripts/Background Tasks/"&pgmToFind&".app' "   
end if
return true
Last edited by kw123 on Sat Sep 07, 2013 9:47 am, edited 2 times in total.

Posted on
Fri Sep 06, 2013 11:37 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: how to make sure a certain program is running

Another all-AppleScript (i.e. doesn't call a shell script) way of determining if an app is running would be

Code: Select all
tell application "System Events"
   set itsRunning to false
   set runningApps to the name of every process
   repeat with thisApp in runningApps
      if text of thisApp is "<name of app as seen in the Finder>" then
         set itsRunning to true
      end if
   end repeat
   if itsRunning is false then
      -- Do things here if the app isn't running.
   end if
end tell

This method might be more useful for applications that have more extensive AppleScript dictionaries (like iTunes or VLC) where you may wish to have the application do a number of things after launching it (or re-launching it).

Posted on
Sat Sep 07, 2013 10:59 am
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: how to make sure a certain program is running

cool

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest