Advertisement
Guest User

lockscreen.sh

a guest
Dec 4th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.72 KB | None | 0 0
  1. #!/bin/bash
  2. ################################################
  3. # Monitor X idle time.  Lock screen when idle.
  4.                            
  5. IDLETIME="5" # in minutes    
  6.                            
  7. ################################################
  8.  
  9. function getidle () {
  10.     # Get idle in seconds instead of ms
  11.     echo $(( $(xprintidle) / 1000))
  12. }
  13.  
  14. function lockscreen () {
  15.     # check for running instance of slimlock
  16.     if [[ $(pgrep slimlock) ]]
  17.     then
  18.         echo "Existing instance detected."
  19.     else
  20.         slimlock
  21.     fi
  22. }
  23.  
  24.  
  25. # minutes to seconds
  26. IDLE=$(($IDLETIME * 60))
  27.  
  28. while true
  29. do
  30.     IDLESEC=$(getidle)
  31.     if (( "$IDLESEC" >= "$IDLE" ))
  32.     then
  33.         lockscreen
  34.         # Reset IDLESEC to force full sleep period
  35.         IDLESEC=0
  36.     fi
  37.     sleep $(( $IDLE - $IDLESEC ))
  38. done
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement