Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## xidles.c
- /* gcc -o xidles xidles.c -lm -lXss */
- #include <stdio.h>
- #include <X11/extensions/scrnsaver.h>
- #include <math.h>
- main() {
- XScreenSaverInfo *info = XScreenSaverAllocInfo();
- Display *display = XOpenDisplay(0);
- XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
- printf("%u\n", (int)ceil((float)info->idle/1000));
- }
- ## idlealarm.sh
- #!/bin/bash
- # you can edit these:
- threshold=1500 # how many seconds to consider idle
- absentidle=1800 # how many seconds to give up and decide you're absent
- function alert_me() {
- if [ -z "$(pgrep -f mplayer.*urandom)" ];then
- sleep 2 && mplayer -profile poly,j4 -demuxer rawaudio -endpos 120 \
- /dev/urandom 2>/dev/null
- fi
- }
- function end_alert() {
- pkill -f mplayer.*urandom
- }
- # end edits
- goneidle=0
- while sleep 1;do
- idletime=$(xidles)
- if [ $idletime -ge $threshold ];then
- [ $goneidle -eq 0 ] && goneidle=1
- [ $idletime -lt $absentidle ] && alert_me &
- else
- [ $goneidle -eq 1 ] && goneidle=0 && end_alert
- fi
- done
- ## idlebastard_alarm.sh
- #!/bin/bash
- # you can edit these:
- threshold=180 # how many seconds to consider idle
- absentidle=480 # how many seconds to give up and decide you're absent
- function alert_me() {
- /home/ze/bin/polysleep_wake.sh
- }
- # end edits
- goneidle=0
- while sleep 1;do
- idletime=$(xidles)
- if [ $idletime -ge $threshold ];then
- [ $idletime -lt $absentidle ] && [ $goneidle -eq 0 ] && alert_me &
- [ $goneidle -eq 0 ] && goneidle=1
- else
- [ $goneidle -eq 1 ] && goneidle=0
- fi
- done
- ## idlelog.sh
- #!/bin/bash
- # you can edit these:
- threshold=420 # how many seconds to consider idle
- longidle=1200 # how many seconds to consider a long idle
- absentidle=1800 # how many seconds to give up and decide you're absent
- answers=(overslept food water "went out" thinking "watched something" bathroom \
- hygiene chores "around the house" nap) # list of standard reasons for being idle
- function alert_me() {
- if [ -z "$(pgrep -f mplayer.*urandom)" ];then
- pkill mplayer
- sleep 2 && mplayer -profile poly,j4 -demuxer rawaudio -endpos 120 \
- /dev/urandom 2>/dev/null
- fi
- }
- # end edits
- goneidle=0
- mkdir -p ~/.idle
- IFS=$'\n'
- function getreason() {
- reason=($(Xdialog --no-close --under-mouse --stdout --editable --check "journal" --no-cancel \
- --combobox "Why idle @ $1?" 0 0 "" "${answers[@]}"))
- reason[0]="${reason[0]//\\/\\\\}"
- reason[0]="${reason[0]//&/\\&}"
- reason[0]="${reason[0]//#/\\#}"
- if [ ${reason[0]/#un} == "checked" ];then
- reason[1]="${reason[0]}"
- reason[0]="unspecified"
- fi
- cat ~/.idle/log >~/.idle/log.old
- cat ~/.idle/log.old | sed -e "s#\(went idle @ $1\) ()#\1 (${reason[0]})#" \
- >~/.idle/log
- [ "${reason[1]}" == "checked" ] && aterm -e vim ~/.journal/$(date +%s)
- }
- while sleep 1;do
- idleplus=$(xidles)
- if [ $idleplus -ge $threshold ];then
- if [ $goneidle -eq 0 ];then
- goneidle=1
- nowtime=$(date +%s)
- idletime=$((nowtime-idleplus))
- reason="$(cat ~/.idle/reason 2>/dev/null)"
- echo "went idle @ $(date -d @$idletime) ($reason)" >>~/.idle/log
- fi
- [ $idleplus -ge $longidle ] && [ $idleplus -lt $absentidle ] && \
- [ -z "$reason" ] && [ -e ~/.idle/sleepy ] && alert_me &
- else
- if [ $goneidle -gt 0 ];then
- goneidle=0
- nowtime=$(date +%s)
- returntime=$((nowtime-idleplus))
- gfs=$((returntime-idletime))
- gonefor="$((gfs/3600/24))d $((gfs/3600%24))h $((gfs/60%60))m $((gfs%60))s"
- echo "came back @ $(date -d @$returntime) ($gonefor)" >>~/.idle/log
- >~/.idle/reason
- [ -z "$reason" ] && getreason "$(date -d @$idletime)" &
- fi
- fi
- done
- ## nap.sh
- #!/bin/bash
- napt=23 # default nap time, if unspecified on commandline
- gapt=70 # minimum time between naps
- mv ~/.naplog ~/.naplog.bak
- grep awake ~/.naplog.bak >~/.naplog
- echo nap >~/.idle/reason
- tsln=$(($(date +%s)-$(date -d "$(tail -n 1 ~/.naplog | cut -d@ -f3)" +%s)))
- [ $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; }
- [ "$1" == "-n" ] && shift && { mplayer -loop -1 -profile poly,js1 -softvol -volume 10 ~/music/ardour2/oceanloop/export/oceanloop.wav & }
- cd ~/tmp/napvlog;dvgrab -d $((${1:-$napt}*60)):45 -s 0 -timesys nap- >/dev/null 2>&1 &
- export DISPLAY=:0.0
- sleep 2
- xset dpms force off
- printf "sleep @ $(date) | " | tee -a ~/.naplog
- read -r -t $((${1:-$napt}*60)) -d $'\4'
- /home/ze/bin/polysleep_wake.sh &
- printf "awake @ $(date)\n" | tee -a ~/.naplog
- ## polysleep_wake.sh
- #!/bin/bash
- export DISPLAY=:0.0
- xset dpms force on -dpms
- bastard=$(uuidgen)
- bastard2=$(uuidgen)
- ln -s /bin/bash ~/tmp/$bastard
- ln -s /home/ze/bin/bastard_alarm ~/tmp/$bastard2
- cd ~/tmp/
- $bastard $bastard2 &
- sleep 1 && rm $bastard $bastard2
- ## bastard_alarm
- #!/bin/bash
- thresh=5 # seconds of inactivity before alarm unpauses
- enti=5 # minutes of cumulative activity before alarm quits
- ffjoy="/dev/input/dragonrise" # reliable dev file for force-feedback device, must work with fftest
- alarms="${HOME}/.alarms" # directory full of alternative alarm sounds
- mplopts="-profile j4m" # extra options to mplayer (my j4m profile just sends 1 channel out to 4)
- # crude sequence for force-feedback device
- # mine does a long low rumble with a few short/hard ones overlayed (seemingly independent, additive)
- # play around with fftest to find appropriate numbers and timings for a desired effect
- # MAKE SURE YOU echo -1 AT THE END OR RISK POSSIBLE SYSTEM LOCKUP FROM BUGGY JOYSTICK DRIVERS!!
- ffseq="echo 0 && sleep 2 && echo 5 && sleep 6 && echo 5 && sleep 6 && echo 5 && sleep 6 && echo -1"
- while getopts :t:e:j:a: OPT;do
- case "$OPT" in
- t) thresh="$OPTARG" ;;
- e) enti="$OPTARG" ;;
- j) ffjoy="$OPTARG" ;;
- a) alarms="$OPTARG" ;;
- :) echo "missing value for option: -$OPTARG" >/dev/stderr; exit 1 ;;
- ?) echo "invalid option: -$OPTARG" >/dev/stderr ;;
- esac
- done
- mifile="${HOME}/.mplayer/alari"
- qfile="/tmp/$$.quit"
- fffile="/tmp/$$.ff"
- pau=0
- acti=0
- function alarm_init() {
- mkfifo $mifile 2>/dev/null
- echo 1 >$fffile
- if [ $(ls $alarms/ 2>/dev/null | wc -l ) -gt 0 ];then
- until [ -e $qfile ];do
- mplayer -input file=$mifile $mplopts -really-quiet -loop -1 $alarms/*
- done &
- else
- until [ -e $qfile ];do
- mplayer -input file=$mifile $mplopts -really-quiet -demuxer rawaudio /dev/urandom
- done &
- fi
- [ -e $ffjoy ] && until [ -e $qfile ];do
- grep -s -q 1 $fffile && ( $ffseq ) | fftest $ffjoy >/dev/null 2>&1 && sleep 1
- done &
- }
- function alarm_pause() {
- [ $1 -eq 1 ] && [ $pau -eq 0 ] && echo "pause" >$mifile && echo 0 >$fffile && pau=1
- [ $1 -eq 0 ] && [ $pau -eq 1 ] && echo "seek +0" >$mifile && echo 1 >$fffile && pau=0
- }
- function alarm_end() {
- touch $qfile
- echo quit >$mifile
- echo 0 >$fffile
- sleep 1
- rm -f $qfile $mifile $fffile
- }
- function cond_pause() {
- [ $(xidles) -ge $thresh ] && return 1
- ((acti++))
- return 0
- }
- function cond_end() {
- [ $acti -gt $((enti*60*4)) ] && return 0
- return 1
- }
- alarm_init
- until cond_end;do
- if cond_pause; then alarm_pause 1
- else alarm_pause 0
- fi
- sleep 0.25
- done
- alarm_end
Add Comment
Please, Sign In to add comment