Re: application watcher / idle detector
Re: application watcher / idle detector
- Subject: Re: application watcher / idle detector
- From: Jolly Roger <email@hidden>
- Date: Wed, 17 Jan 2001 18:47:25 -0600
- Replyto: email@hidden
on 1/17/2001 5:31 PM, Ken Victor wrote:
>
At 5:04 PM -0600 1/17/01, Jolly Roger wrote:
>
> on 1/17/2001 12:56 PM, Stephen Gross wrote:
>
>
>
>> Problem: A lot of users at my workplace forget to quit applications.
>
>> Possible solution: An applescript that monitors idle applications and
>
>> closes them after a set time.
>
>>
>
>> I know how to write a script to do some of that solution, but not all of
>
>> it. In particular, if anyone knows how to:
>
>>
>
>> (1) Monitor an application's idle time, or
>
>> (2) Stay idle for awhile, then do its idle-checking routine,
>
>
>
> There is no built-in support in classic Mac OS to determine whether or not
>
> an application is currently in use. You might be able to observe which
>
> application is currently front-most, and/or maybe determine if the app has
>
> windows open, and make assumptions based on those observations; but there is
>
> no way that I know of to truly determine if an app is in use or not. With
>
> some work, you could come close; but as long as you make assumptions, you're
>
> taking the risk that you might quit an app that is currently in use.
>
>
>
I don't know of any osax that will tell you whether or not an app has
>
been active or idle, but you might be able to write one. I believe
>
the toolbox call GetProcessInfo will return either how much CPU time
>
the app has used, or the amount of idle time, and the time the app
>
was launched. from whatever numbers are there, I believe you could
>
detect if the app is active or not. but it might not be 100% accurate
>
as if it is the foreground app, it might be getting null events and
>
thus using some processing time to process these null events.
>
ken
I assume you mean the processActiveTime field of the ProcessInfoRec record
returned by GetProcessInfo().
From the docs:
processActiveTime
The accumulated time, in ticks, during which the process has used
the CPU, including both foreground and background processing time.
You'd have to monitor this field for a certain amount of time, noting how
much time is added since the last time you called GetProcessInfo(), and then
deduce from that whether the process is idle or not.
The problem is, there is no standard by which to measure - every application
uses a different amount of CPU time during idle, due to variations in event
loop code, and event handling techniques. No two applications are the same.
While 240 ticks may indicate that application A is idling, 42000 ticks may
indicate that application B is idling, and so on. It's completely dependant
on what the apps actually do during idle. The data returned by
GetProcessInfo() would only be useful if you took that into account.
Like I said, there is no built-in support in classic Mac OS to determine
whether or not an application is idle. And I don't see an easy way to do
what Stephen is looking to do. He should probably take a different approach
to this problem.
JR