You are not logged in.
Pages: 1
Hello
I have a pretty old laptop (Dell Inspiron E1505) with a very short battery life (on the order of a minute) and a loose power cable. I would like to trigger my screen locker (/usr/bin/slock) when I lose AC power. However, I tried to enter this into acpid's handler.sh, but no slock. I am certainly not looking exclusively for an acpid solution either.
The result of systemctl status acpid:
acpid.service - ACPI event daemon
Loaded: loaded (/usr/lib/systemd/system/acpid.service; enabled)
Active: active (running) since Fri 2014-02-07 12:22:16 CST; 20min ago
Main PID: 233 (acpid)
CGroup: /system.slice/acpid.service
└─233 /usr/bin/acpid -f
Feb 07 12:27:14 ollie logger[391]: ACPI group/action undefined: video/switchmode / VMOD
Feb 07 12:30:28 ollie logger[551]: ACPI group/action undefined: video/brightnessdown / BRTDN
Feb 07 12:30:28 ollie logger[553]: ACPI group/action undefined: video/brightnessdown / BRTDN
Feb 07 12:30:28 ollie logger[561]: ACPI group/action undefined: video/brightnessdown / BRTDN
Feb 07 12:30:29 ollie logger[579]: ACPI group/action undefined: video/brightnessdown / BRTDN
Feb 07 12:30:29 ollie logger[581]: ACPI group/action undefined: video/brightnessdown / BRTDN
Feb 07 12:30:34 ollie logger[617]: ACPI group/action undefined: video/brightnessup / BRTUP
Feb 07 12:30:38 ollie logger[667]: ACPI group/action undefined: video/brightnessdown / BRTDN
Feb 07 12:30:38 ollie logger[677]: ACPI group/action undefined: video/brightnessdown / BRTDN
Feb 07 12:35:35 ollie logger[773]: ACPI group/action undefined: processor / LNXCPU:00#!/bin/bash
# Default acpi script that takes an entry for all actions
case "$1" in
button/power)
case "$2" in
PBTN|PWRF)
logger 'PowerButton pressed'
;;
*)
logger "ACPI action undefined: $2"
;;
esac
;;
button/sleep)
case "$2" in
SLPB|SBTN)
logger 'SleepButton pressed'
;;
*)
logger "ACPI action undefined: $2"
;;
esac
;;
ac_adapter)
case "$2" in
AC|ACAD|ADP0)
case "$4" in
00000000)
logger 'AC unpluged'
/usr/bin/slock &
;;
00000001)
logger 'AC pluged'
;;
esac
;;
*)
logger "ACPI action undefined: $2"
;;
esac
;;
battery)
case "$2" in
BAT0)
case "$4" in
00000000)
logger 'Battery online'
;;
00000001)
logger 'Battery offline'
;;
esac
;;
CPU0)
;;
*) logger "ACPI action undefined: $2" ;;
esac
;;
button/lid)
case "$3" in
close)
logger 'LID closed'
/etc/acpi/scripts/lid-close &
;;
open)
logger 'LID opened'
/etc/acpi/scripts/lid-open &
;;
*)
logger "ACPI action undefined: $3"
;;
esac
;;
*)
logger "ACPI group/action undefined: $1 / $2"
;;
esac
# vim:set ts=4 sw=4 ft=sh et:and this is what is logged in journalctl when I unplug my power cord and then plug it back in:
Feb 07 12:36:37 ollie logger[781]: ACPI action undefined: ACPI0003:00
Feb 07 12:36:37 ollie logger[783]: ACPI group/action undefined: processor / LNXCPU:00
Feb 07 12:36:37 ollie logger[785]: ACPI group/action undefined: processor / LNXCPU:01
Feb 07 12:36:38 ollie logger[787]: ACPI action undefined: ACPI0003:00
Feb 07 12:36:38 ollie logger[789]: ACPI group/action undefined: processor / LNXCPU:00
Feb 07 12:36:38 ollie logger[791]: ACPI group/action undefined: processor / LNXCPU:01Thanks!
Last edited by NClement (2014-02-07 19:06:20)
Offline
Try using a Udev rule for that:
This Udev rule will automatically detect whether your laptop runs on battery or not and then runs slock accordingly.
You have to experiment whether it is 0 or 1 though.
/etc/udev/rules.d/50-slock-battery.rules
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/bin/slock"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/bin/slock"Last edited by orschiro (2014-02-08 09:18:56)
Offline
My ACPI handler detects mains power turning on/off, and runs a script.
Offline
Okay, so the did what I asked for, but as it turns out I asked for the wrong thing. Slock is getting triggered just fine, but it is seg faulting every time I unplug my laptop - I am pretty sure because it need to be run from within an X session. It needs to know the display I am trying to slock. Is there a way to hand the X display to slock somehow? Otherwise is there some udev variable I can keep querying in order to check the power supply status? The POWER_SUPPLY_ONLINE=0 does seem to be the right thing, but can check that from my own script?
Offline
@NClement
Try prepending DISPLAY:
/etc/udev/rules.d/50-slock-battery.rules
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="export DISPLAY:0 ; /usr/bin/slock"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="export DISPLAY:0 ; /usr/bin/slock"Offline
See display in udev, for correct method(s).
Offline
Pages: 1