You are not logged in.

#1 2012-09-13 12:52:34

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Bash suspend with xautolock script

Hi
I try write script whose have check if laptop is discharged or charged and matches right xautolock options.
If xautolock is running, i want kill him and run again.

But i have a trouble.

This is my script:

check(){
if grep -Fxq "Discharging" /sys/class/power_supply/BAT0/status;
then
	echo "BATTERY!" && xautolock -time 10 -locker "systemctl suspend" &
else 
	echo "AC POWER!" && xautolock -time 30 -locker "systemctl suspend" &
fi
}
#function kill xautolock process if found him, if not run check function
kill_xautolock(){

	if [ -n "$(pidof xautolock)" ]
	then 
		killall xautolock && check
	else 
		check
	fi
}
while true; do
kill_xautolock
sleep 10
done

I can't kill xautolock by no means. This way not working.

Can anybody help me, because I thinking about it whole day and i don't know what is wrong.

Offline

#2 2012-09-13 13:17:25

progandy
Member
Registered: 2012-05-17
Posts: 5,279

Re: Bash suspend with xautolock script

Why don't you try "xautolock -exit"? Also you kill xautlock every 10 seconds and then restart it, you should kill it only when the discharging status changes.

Last edited by progandy (2012-09-13 13:19:06)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2012-09-13 14:29:25

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: Bash suspend with xautolock script

This is the point. xautolock don't want be dead with killall command, and even by -exit option... This is what i can't fix.

And you're right i should kill it only when dischargins changed, but i haven't idea how do this...

Offline

Board footer

Powered by FluxBB