You are not logged in.

#1 2005-07-13 10:43:20

nightfrost
Member
From: Sweden
Registered: 2005-04-16
Posts: 647

action after idle time

I'm wondering if there's any daemon or anything of the kind that will perform a  user defined action after a certain idle time has passed. Particularly, I would like to have my laptop go into sleep/suspend after a certain time of inactivity. Also, related to this, I would like my laptop to hibernate when there's X% battery life left.

Any ideas of how to do any of this?

(btw, I'd prefer not using klaptop).

Offline

#2 2005-07-13 17:04:10

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: action after idle time

hmmm hibernating based on power would be an acpi event...
as for the idle time... maybe you could implement this through xscreensaver somehow... I don't really know any other app that measures X usage...

Offline

#3 2005-07-13 17:11:29

nightfrost
Member
From: Sweden
Registered: 2005-04-16
Posts: 647

Re: action after idle time

Thanks for the tip with xscreensaver, I'll check it out.

With acpi event, do you mean something that I can configure with acpid, then? i.e. define an event tied to, say, the result of "cat /proc/acpi/battery/CMB1/state | grep mAh"...

Offline

#4 2005-07-13 17:50:23

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: action after idle time

nightfrost wrote:

With acpi event, do you mean something that I can configure with acpid, then? i.e. define an event tied to, say, the result of "cat /proc/acpi/battery/CMB1/state | grep mAh"...

well, I did some looking around... acpid doesn't expose battery levels through events, however, the gentoo wiki has the following script to poll battery status:

LIMIT="200" ## Suspend if battery level drops below this (in mAh/mWh)
SLEEP="60"  ## Seconds between each battery level check
BAT="BAT1" ## Part of path: /proc/acpi/battery/BAT/
HIBERNATE="/usr/local/sbin/hibernate" ## command used to suspend
#HIBERNATE="echo 4 > /proc/acpi/sleep"

while [ true ]; do
  if [ -e "/proc/acpi/battery/$BAT/state" ]; then
     PRESENT=$(/bin/sed -ne
      "/present:/{s/^present:[ ]*([a-z]*)$/1/p;q}"
      /proc/acpi/battery/$BAT/state)
     #echo $PRESENT
     if [ "$PRESENT" = "yes" ]; then
        STATE=$(/bin/sed -ne
         "/charging state:/{s/^charging state:[ ]*([a-zA-Z]*)$/1/p;q}"
         /proc/acpi/battery/$BAT/state)
        BATTERY=$(/bin/sed -ne
         "/remaining capacity:/{s/^remaining capacity:[ ]*([0-9]*) m[WA]h$/1/p;q}"
         /proc/acpi/battery/$BAT/state)
        #echo $BATTERY
        #echo $STATE
        if [ "$BATTERY" -lt "$LIMIT" ] && [ "$STATE" = "discharging" ]; then

           ## Comment out the following line if you don't
           ## want to log the event to system log:
           logger "Battery at ${BATTERY} mWh. Suspending to disk."
           #echo "Battery at ${BATTERY} mWh. Suspending to disk."

           ## Suspend:
           exec "$HIBERNATE"
       fi
     fi
  fi
  sleep ${SLEEP}s
done

Offline

#5 2005-07-13 18:44:54

nightfrost
Member
From: Sweden
Registered: 2005-04-16
Posts: 647

Re: action after idle time

Cheers! I'm gonna try that script out. It seems like what I've been looking for.

Offline

#6 2005-07-13 21:39:52

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: action after idle time

The only thing I don't like about it is you won't have any warning... you'll just be typing and BAM, hibernate...

I'd think it'd be better if it's interactive... which would require something more than a bash script... any pythin gurus want to bust something out?

Offline

#7 2005-07-13 21:49:48

nightfrost
Member
From: Sweden
Registered: 2005-04-16
Posts: 647

Re: action after idle time

Sure, when you mention it that would be nice... However, this simple script serves my purposes. I mainly want something to save me those odd moments when I've run off to do something, and completely forgotten my laptop is on battery. Instead of having my unsaved work lost, a hibernate would save my day...

Offline

#8 2005-07-13 22:57:26

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: action after idle time

ahhh good point

Offline

Board footer

Powered by FluxBB