Xprintidle is a utility that queries the X server for the user’s idle time and prints it to stdout (in milliseconds). You could use it to check if anyone was sitting on your computer while you were away or even write scripts to perfom simple tasks like limiting your total idle time or send mails and notices.
# apt-get install xprintidle
while [ 1 ];
if [ `xprintidle` -gt 120000 ];
notify-send "You have been idle for 2 mins"
This script will send a notification when idle is more than 2mins and stop.