[futurebasic] Re: [FB] Amnesia

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2004 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Tue, 7 Sep 2004 10:33:07 +1200
Michael Evans wrote:

> I would like to write an application (let's call it amnesia for ease 
> of reference) that that checks the list of running applications 
> (processes) every nn seconds. If amnesia detects that a certain 
> application is running,  it emits a sound or spoken warning. An abilty 
> to adjust the volume of the emitted sound is important.
>
> I think I need the process manager to list the running processes but I 
> can't find anything germane in the examples.

The demo below sleeps quietly for _sleepSeconds, consuming no CPU 
resources, then wakes up briefly to perform the check.

'--------------------
local mode
local fn IsProcesssRunning( theProcess as Str255 )
'~'1
dim as long                 index
dim as Str255               processName
dim as ProcessSerialNumber  psn
dim as Boolean              running

running = _false
index   = 1
do
psn.highLongOfPSN = 0
psn.lowLongOfPSN  = 0
GetProcessInfo index, processName, psn
long if ( psn.highLongOfPSN or psn.lowLongOfPSN )
long if ( processName == theProcess )
running = _zTrue
exit fn
end  if
end if
index++
until ( (psn.highLongOfPSN or psn.lowLongOfPSN) == 0 )
end fn = running


local mode
local fn DoEvent
'~'1
dim ev as ^EventRecord

ev = event
long if ( ev.what == _nullEvt )
if fn IsProcesssRunning( "FB3 Compiler" ) then beep
end if
end fn


// main program
_sleepSeconds = 5 // interval between checks
poke long event - 8, 60*_sleepSeconds // ticks between null events
on event fn DoEvent
do
HandleEvents
until 0
'--------------------

Robert P.