Search code examples
pythonobjective-cmacosmouseeventosx-snow-leopard

Detect when computer becomes active?


I am having trouble finding an answer of how I could do this.

Basically what I want is to have a program start automatically when it detects that I am using the computer. So for example say I stop using the computer for a few hours and then come back, it would detect this and then open another program or something.

I am looking for a solution in Ruby/python/objective c/Applescript preferably. But anything would work.

I'd like it to work on Snow Leopard.

Any suggestions would be great!


Solution

  • You can monitor all events in the system using NSEvent addGlobalMonitor.... Keep track of the time between two successive events, if it's over a treshold, it means the user was inactive for that time.