Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
improving a script for working with X idle time
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
andi456
Apprentice
Apprentice


Joined: 06 Mar 2005
Posts: 157
Location: Germany

PostPosted: Sun Jun 21, 2020 10:45 am    Post subject: improving a script for working with X idle time Reply with quote

Hi,

my script for sending the computer into suspend mode after certain period of idle time in X is a more or less dirty hack. That's why I'm looking for some improvements. It usually runs under the awesome window manager using xssstate for checking the idle time. It should be able to decide, if a certain variable is set, and then enter suspend mode or not. In my version the variable is sourced from the hard drive, which i would like to avoid in the future.

Code:

#!/bin/sh

if [ $# -lt 2 ];
then
    printf "usage: %s minutes command\n" "$(basename $0)" 2>&1
    exit 1
fi

timeout=$(($1*60*1000))
shift
cmd="$@"
triggered=false
if [ -e ~/.config/toggle-pm-suspendrc ];
then
    source ~/.config/toggle-pm-suspendrc
fi
if [ $ENABLED -eq 1 ];
then
    echo "Will trigger $cmd after $timeout Milliseconds"
else
   echo "Trigger disabled by user."
fi
while true
do
    tosleep=$(((timeout - $(xssstate -i)) / 1000))
    if [ $tosleep -le 0 ];
    then
        source ~/.config/toggle-pm-suspendrc
        if [ $ENABLED -eq 1 ];
        then
            logger 'will execute' $cmd
            $triggered || $cmd
            triggered=true
        else
            echo "Trigger disabled by user"
        fi
    else
        triggered=false
        sleep $tosleep
    fi
done


Thanks in advance,

Kind regards,

Andreas
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum