Guest User

Untitled

a guest
Jan 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. ## xidles.c
  2. /* gcc -o xidles xidles.c -lm -lXss */
  3. #include <stdio.h>
  4. #include <X11/extensions/scrnsaver.h>
  5. #include <math.h>
  6.  
  7. main() {
  8. XScreenSaverInfo *info = XScreenSaverAllocInfo();
  9. Display *display = XOpenDisplay(0);
  10.  
  11. XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
  12. printf("%u\n", (int)ceil((float)info->idle/1000));
  13. }
  14. ## idlealarm.sh
  15. #!/bin/bash
  16. # you can edit these:
  17. threshold=1500 # how many seconds to consider idle
  18. absentidle=1800 # how many seconds to give up and decide you're absent
  19. function alert_me() {
  20. if [ -z "$(pgrep -f mplayer.*urandom)" ];then
  21. sleep 2 && mplayer -profile poly,j4 -demuxer rawaudio -endpos 120 \
  22. /dev/urandom 2>/dev/null
  23. fi
  24. }
  25. function end_alert() {
  26. pkill -f mplayer.*urandom
  27. }
  28. # end edits
  29.  
  30. goneidle=0
  31. while sleep 1;do
  32. idletime=$(xidles)
  33. if [ $idletime -ge $threshold ];then
  34. [ $goneidle -eq 0 ] && goneidle=1
  35. [ $idletime -lt $absentidle ] && alert_me &
  36. else
  37. [ $goneidle -eq 1 ] && goneidle=0 && end_alert
  38. fi
  39. done
  40. ## idlebastard_alarm.sh
  41. #!/bin/bash
  42. # you can edit these:
  43. threshold=180 # how many seconds to consider idle
  44. absentidle=480 # how many seconds to give up and decide you're absent
  45. function alert_me() {
  46. /home/ze/bin/polysleep_wake.sh
  47. }
  48. # end edits
  49.  
  50. goneidle=0
  51. while sleep 1;do
  52. idletime=$(xidles)
  53. if [ $idletime -ge $threshold ];then
  54. [ $idletime -lt $absentidle ] && [ $goneidle -eq 0 ] && alert_me &
  55. [ $goneidle -eq 0 ] && goneidle=1
  56. else
  57. [ $goneidle -eq 1 ] && goneidle=0
  58. fi
  59. done
  60. ## idlelog.sh
  61. #!/bin/bash
  62. # you can edit these:
  63. threshold=420 # how many seconds to consider idle
  64. longidle=1200 # how many seconds to consider a long idle
  65. absentidle=1800 # how many seconds to give up and decide you're absent
  66. answers=(overslept food water "went out" thinking "watched something" bathroom \
  67. hygiene chores "around the house" nap) # list of standard reasons for being idle
  68. function alert_me() {
  69. if [ -z "$(pgrep -f mplayer.*urandom)" ];then
  70. pkill mplayer
  71. sleep 2 && mplayer -profile poly,j4 -demuxer rawaudio -endpos 120 \
  72. /dev/urandom 2>/dev/null
  73. fi
  74. }
  75. # end edits
  76.  
  77. goneidle=0
  78. mkdir -p ~/.idle
  79. IFS=$'\n'
  80. function getreason() {
  81. reason=($(Xdialog --no-close --under-mouse --stdout --editable --check "journal" --no-cancel \
  82. --combobox "Why idle @ $1?" 0 0 "" "${answers[@]}"))
  83. reason[0]="${reason[0]//\\/\\\\}"
  84. reason[0]="${reason[0]//&/\\&}"
  85. reason[0]="${reason[0]//#/\\#}"
  86. if [ ${reason[0]/#un} == "checked" ];then
  87. reason[1]="${reason[0]}"
  88. reason[0]="unspecified"
  89. fi
  90. cat ~/.idle/log >~/.idle/log.old
  91. cat ~/.idle/log.old | sed -e "s#\(went idle @ $1\) ()#\1 (${reason[0]})#" \
  92. >~/.idle/log
  93. [ "${reason[1]}" == "checked" ] && aterm -e vim ~/.journal/$(date +%s)
  94. }
  95. while sleep 1;do
  96. idleplus=$(xidles)
  97. if [ $idleplus -ge $threshold ];then
  98. if [ $goneidle -eq 0 ];then
  99. goneidle=1
  100. nowtime=$(date +%s)
  101. idletime=$((nowtime-idleplus))
  102. reason="$(cat ~/.idle/reason 2>/dev/null)"
  103. echo "went idle @ $(date -d @$idletime) ($reason)" >>~/.idle/log
  104. fi
  105. [ $idleplus -ge $longidle ] && [ $idleplus -lt $absentidle ] && \
  106. [ -z "$reason" ] && [ -e ~/.idle/sleepy ] && alert_me &
  107. else
  108. if [ $goneidle -gt 0 ];then
  109. goneidle=0
  110. nowtime=$(date +%s)
  111. returntime=$((nowtime-idleplus))
  112. gfs=$((returntime-idletime))
  113. gonefor="$((gfs/3600/24))d $((gfs/3600%24))h $((gfs/60%60))m $((gfs%60))s"
  114. echo "came back @ $(date -d @$returntime) ($gonefor)" >>~/.idle/log
  115. >~/.idle/reason
  116. [ -z "$reason" ] && getreason "$(date -d @$idletime)" &
  117. fi
  118. fi
  119. done
  120. ## nap.sh
  121. #!/bin/bash
  122. napt=23 # default nap time, if unspecified on commandline
  123. gapt=70 # minimum time between naps
  124. mv ~/.naplog ~/.naplog.bak
  125. grep awake ~/.naplog.bak >~/.naplog
  126. echo nap >~/.idle/reason
  127. tsln=$(($(date +%s)-$(date -d "$(tail -n 1 ~/.naplog | cut -d@ -f3)" +%s)))
  128. [ $tsln -lt $((gapt*60)) ] && { printf "Only $(($tsln/60))min since last nap.";mplayer -profile poly,j4m -endpos 0.2 -demuxer rawaudio /dev/urandom;echo;exit 1; }
  129. [ "$1" == "-n" ] && shift && { mplayer -loop -1 -profile poly,js1 -softvol -volume 10 ~/music/ardour2/oceanloop/export/oceanloop.wav & }
  130. cd ~/tmp/napvlog;dvgrab -d $((${1:-$napt}*60)):45 -s 0 -timesys nap- >/dev/null 2>&1 &
  131. export DISPLAY=:0.0
  132. sleep 2
  133. xset dpms force off
  134. printf "sleep @ $(date) | " | tee -a ~/.naplog
  135. read -r -t $((${1:-$napt}*60)) -d $'\4'
  136. /home/ze/bin/polysleep_wake.sh &
  137. printf "awake @ $(date)\n" | tee -a ~/.naplog
  138. ## polysleep_wake.sh
  139. #!/bin/bash
  140. export DISPLAY=:0.0
  141. xset dpms force on -dpms
  142. bastard=$(uuidgen)
  143. bastard2=$(uuidgen)
  144. ln -s /bin/bash ~/tmp/$bastard
  145. ln -s /home/ze/bin/bastard_alarm ~/tmp/$bastard2
  146. cd ~/tmp/
  147. $bastard $bastard2 &
  148. sleep 1 && rm $bastard $bastard2
  149. ## bastard_alarm
  150. #!/bin/bash
  151. thresh=5 # seconds of inactivity before alarm unpauses
  152. enti=5 # minutes of cumulative activity before alarm quits
  153. ffjoy="/dev/input/dragonrise" # reliable dev file for force-feedback device, must work with fftest
  154. alarms="${HOME}/.alarms" # directory full of alternative alarm sounds
  155. mplopts="-profile j4m" # extra options to mplayer (my j4m profile just sends 1 channel out to 4)
  156.  
  157. # crude sequence for force-feedback device
  158. # mine does a long low rumble with a few short/hard ones overlayed (seemingly independent, additive)
  159. # play around with fftest to find appropriate numbers and timings for a desired effect
  160. # MAKE SURE YOU echo -1 AT THE END OR RISK POSSIBLE SYSTEM LOCKUP FROM BUGGY JOYSTICK DRIVERS!!
  161. ffseq="echo 0 && sleep 2 && echo 5 && sleep 6 && echo 5 && sleep 6 && echo 5 && sleep 6 && echo -1"
  162.  
  163. while getopts :t:e:j:a: OPT;do
  164. case "$OPT" in
  165. t) thresh="$OPTARG" ;;
  166. e) enti="$OPTARG" ;;
  167. j) ffjoy="$OPTARG" ;;
  168. a) alarms="$OPTARG" ;;
  169. :) echo "missing value for option: -$OPTARG" >/dev/stderr; exit 1 ;;
  170. ?) echo "invalid option: -$OPTARG" >/dev/stderr ;;
  171. esac
  172. done
  173. mifile="${HOME}/.mplayer/alari"
  174. qfile="/tmp/$$.quit"
  175. fffile="/tmp/$$.ff"
  176. pau=0
  177. acti=0
  178.  
  179. function alarm_init() {
  180. mkfifo $mifile 2>/dev/null
  181. echo 1 >$fffile
  182. if [ $(ls $alarms/ 2>/dev/null | wc -l ) -gt 0 ];then
  183. until [ -e $qfile ];do
  184. mplayer -input file=$mifile $mplopts -really-quiet -loop -1 $alarms/*
  185. done &
  186. else
  187. until [ -e $qfile ];do
  188. mplayer -input file=$mifile $mplopts -really-quiet -demuxer rawaudio /dev/urandom
  189. done &
  190. fi
  191. [ -e $ffjoy ] && until [ -e $qfile ];do
  192. grep -s -q 1 $fffile && ( $ffseq ) | fftest $ffjoy >/dev/null 2>&1 && sleep 1
  193. done &
  194. }
  195. function alarm_pause() {
  196. [ $1 -eq 1 ] && [ $pau -eq 0 ] && echo "pause" >$mifile && echo 0 >$fffile && pau=1
  197. [ $1 -eq 0 ] && [ $pau -eq 1 ] && echo "seek +0" >$mifile && echo 1 >$fffile && pau=0
  198. }
  199. function alarm_end() {
  200. touch $qfile
  201. echo quit >$mifile
  202. echo 0 >$fffile
  203. sleep 1
  204. rm -f $qfile $mifile $fffile
  205. }
  206. function cond_pause() {
  207. [ $(xidles) -ge $thresh ] && return 1
  208. ((acti++))
  209. return 0
  210. }
  211. function cond_end() {
  212. [ $acti -gt $((enti*60*4)) ] && return 0
  213. return 1
  214. }
  215.  
  216. alarm_init
  217. until cond_end;do
  218. if cond_pause; then alarm_pause 1
  219. else alarm_pause 0
  220. fi
  221. sleep 0.25
  222. done
  223. alarm_end
Add Comment
Please, Sign In to add comment