Page 1 of 1

Programms running?

Posted: Mon Jan 23, 2012 1:35 am
by raulvelazquez
Is there a way, on a PC and Mac, to see if there is a program running?
To explain better, I want to make a video player, but I want to check if there is a program that is running that can make captures, like Camtasia. If there is, I would like to stop my program and tell the user that it should close X program.

Can that be done using LiveCode?

Re: Programms running?

Posted: Sun Jan 29, 2012 7:30 am
by spencer
Sons of Thunder has code to do find processes:



http://www.sonsothunder.com/devres/revo ... roc002.htm

This assumes you have a good understanding of what a process is and how to identify a process you'd like to manipulate . If you don’t, take a look at tip proc005 - Understanding Processes before continuing.
The Macintosh portion of this code is implemented in AppleScript, and the Windows portion is implemented using the PrcView* command line utility, and assumes that you have put the pv.exe application in the same directory as your standalone (i.e. the default "directory").

function ProcessList
switch (the platform)
case "MacOS"
put "tell application" && q("Finder") && cr & \
"set procList to the processes" & cr & \
"set procNames to" && q("") & cr & \
"repeat with p in procList" & cr & \
"set procNames to procNames & the name of p & ascii character 10" & cr & \
"end repeat" & cr & \
"return procNames" & cr & \
"end tell" into tScript
do tScript as AppleScript
put the result into tProcesses
delete char 1 of tProcesses -- removes preceding quote
delete last char of tProcesses -- removes trailing quote
break
case "Win32"
set the hideConsoleWindows to true
put shell("pv -q") into tProcList
put "" into tProcesses
set the itemDel to tab
repeat for each line tProc in tProcList
put item 1 of tProc into tProc
append tProc,tProcesses
end repeat
break
end switch
return tProcesses
end ProcessList

function q what
return quote & what & quote
end q

on append what,@toWhat
put what into line (the number of lines of toWhat)+1 of toWhat
end append
Note that the use of ascii character 10 is needed because the AppleScript separates the names with a "return" which to AppleScript is ascii 13. MC/Rev uses ascii 10 for an end of line instead. Also note that the first and last characters of the returned value will be quotes, so you'll need to remove them in your script once you have the data. Also note that there is a second or so delay in getting the list of processes from AppleScript, so you should put up a watch just before the call.
* PrcView is a command line utility developed by Igor Nys, and can be downloaded at http://www.prcview.com/. PrcView is free for personal use or to be distributed with freeware applications; for shareware or commercial use, please contact Igor. Licensing costs are very reasonable, and he is very willing to work with you to make it worth your while to use his application.


Mac Version: Originally posted 7/21/2002 by Sarah Reichelt to the Use-Revolution List (See the complete post/thread)

Combined version posted 12/26/2002 by Ken Ray

Re: Programms running?

Posted: Sun Jan 29, 2012 12:43 pm
by Mark
Hi,

Here's my version. Probably a combination for this one and Sarah's would be best.

Code: Select all

function programs
     if the platform is "MacOS" then -- only OSX!
          put shell("ps -xcw") into myList
          put offset("COMMAND",myList) into myColPos
          repeat for each line myLine in myList
               put char myColPos to -1 of myLine & cr after myNewList
          end repeat
          filter myNewList without "(*"
          return line 2 to -1 of myNewList
     else if the platform is "Win32" then
          put line 4 to -1 of shell("tasklist") into myList
          // or use the pv command as in Sarah's script
          repeat for each line myLine in myList
               put word 1 of myLine & cr after myNewList
          end repeat
          return line 1 to -2 of myNewList
     else
          return empty
     end if
end programs
I believe you can use the Mac OS X part of this script for Linux as well.

Kind regards,

Mark