applescript - How to detect if user is away in OSX? -


i want start script when user goes away or returns computer. there built-in method in applescript check user's state? if not else can use in osx?

here's command might work you. tell how long it's been since mouse moved or keystroke pressed.

set idletime shell script "ioreg -c iohidsystem | awk '/hididletime/ {print $nf/1000000000; exit}'" 

so might assume if no key pressed or mouse moved period of time user not using computer. clever tracking of idletime can tell when user left computer , when returned. this.

save applescript application , check "stay open after run handler" checkbox. can quit time right-clicking on dock icon , choosing quit.

global timebeforecomputerisnotinuse, computerisinuse, previousidletime  on run     set timebeforecomputerisnotinuse 300 -- 5 minutes     set computerisinuse true     set previousidletime 0 end run  on idle     set idletime (do shell script "ioreg -c iohidsystem | awk '/hididletime/ {print $nf/1000000000; exit}'") number      if not computerisinuse         if idletime less previousidletime             set computerisinuse true             "user using computer again."         end if     else if idletime greater or equal timebeforecomputerisnotinuse         set computerisinuse false         "user has left computer."     end if      set previousidletime idletime     return 1 end idle 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -