Here is a team that can work for you. This will show you how much time has passed since moving the mouse or pressing a key.
set idleTime to do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'"
Thus, you can assume that if no key has been pressed, or the mouse has not been moved for a certain period of time, the user is not using the computer. With some clever tracking idleTime you can tell when the user leaves the computer, and when he returned. Something like that.
Save it as an applescript application and check the box "to remain open after the launch." You can withdraw from it at any time by right-clicking the Dock icon, and selecting "Exit".
global timeBeforeComputerIsNotInUse, computerIsInUse, previousIdleTime on run set timeBeforeComputerIsNotInUse to 300 -- 5 minutes set computerIsInUse to true set previousIdleTime to 0 end run on idle set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'") as number if not computerIsInUse then if idleTime is less than previousIdleTime then set computerIsInUse to true say "User is using the computer again." end if else if idleTime is greater than or equal to timeBeforeComputerIsNotInUse then set computerIsInUse to false say "User has left the computer." end if set previousIdleTime to idleTime return 1 end idle ioreg -c IOHIDSystem | awk '/ HIDIdleTime / {print $ NF / global timeBeforeComputerIsNotInUse, computerIsInUse, previousIdleTime on run set timeBeforeComputerIsNotInUse to 300 -- 5 minutes set computerIsInUse to true set previousIdleTime to 0 end run on idle set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'") as number if not computerIsInUse then if idleTime is less than previousIdleTime then set computerIsInUse to true say "User is using the computer again." end if else if idleTime is greater than or equal to timeBeforeComputerIsNotInUse then set computerIsInUse to false say "User has left the computer." end if set previousIdleTime to idleTime return 1 end idle ." global timeBeforeComputerIsNotInUse, computerIsInUse, previousIdleTime on run set timeBeforeComputerIsNotInUse to 300 -- 5 minutes set computerIsInUse to true set previousIdleTime to 0 end run on idle set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'") as number if not computerIsInUse then if idleTime is less than previousIdleTime then set computerIsInUse to true say "User is using the computer again." end if else if idleTime is greater than or equal to timeBeforeComputerIsNotInUse then set computerIsInUse to false say "User has left the computer." end if set previousIdleTime to idleTime return 1 end idle to timeBeforeComputerIsNotInUse then global timeBeforeComputerIsNotInUse, computerIsInUse, previousIdleTime on run set timeBeforeComputerIsNotInUse to 300 -- 5 minutes set computerIsInUse to true set previousIdleTime to 0 end run on idle set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'") as number if not computerIsInUse then if idleTime is less than previousIdleTime then set computerIsInUse to true say "User is using the computer again." end if else if idleTime is greater than or equal to timeBeforeComputerIsNotInUse then set computerIsInUse to false say "User has left the computer." end if set previousIdleTime to idleTime return 1 end idle " global timeBeforeComputerIsNotInUse, computerIsInUse, previousIdleTime on run set timeBeforeComputerIsNotInUse to 300 -- 5 minutes set computerIsInUse to true set previousIdleTime to 0 end run on idle set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'") as number if not computerIsInUse then if idleTime is less than previousIdleTime then set computerIsInUse to true say "User is using the computer again." end if else if idleTime is greater than or equal to timeBeforeComputerIsNotInUse then set computerIsInUse to false say "User has left the computer." end if set previousIdleTime to idleTime return 1 end idle
source share