sudo apt-get install xautolock
xautolock - fire up programs in case of user inactivity under X
Specifies the primary timeout interval. The default is 10 minutes, the minimum is 1 minute, and the maximum is 1 hour.
Specifies the locker to be used. The default is xlock. Notice that if locker contains multiple words, it must be specified between quotes. In order to use your PATH to locate the program, xautolock feeds the locker command to /bin/sh, so it should be understandable for whatever shell your /bin/sh is. Because this typically is a Bourne shell, ~ expansion most likely will not work.
For a quick 1 minute idle time test use -time 1
xautolock -notify 10 -notifier 'notify-send -i firefox "Firefox will close in 10 seconds"' -time 10 -locker "pkill firefox"