You are not logged in.
I have written a script to change my display brightness level depending on the power state ( battery or AC) called backlightAlter.sh.
It's content has:
#!/usr/bin/sudo bash
if [[ $1 == true ]]
then
echo 174 > /sys/class/backlight/intel_backlight/brightness
elif [[ $1 == false ]]
then
echo 454 > /sys/class/backlight/intel_backlight/brightness
else
echo Unknow parameter!
fi
And an udev rule file called power_save.rules with:
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/innerpeace/.Xauthority", RUN+="sudo /usr/local/bin/backlightAlter.sh true"
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/innerpeace/.Xauthority", RUN+="sudo /usr/local/bin/backlightAlter.sh false"
When I plugged or unplugged the power supply the systemd-udev.service display this:
AC: Process 'sudo /usr/local/bin/backlightAlter.sh false' failed with exit code 1.
Does anyone make me out!.
P/S: when I try to run backlightAlter.sh from the terminal it worked well, but not for from udev.
Last edited by innerpeace (2022-08-15 12:29:32)
Offline
You don't need '#!/usr/bin/sudo bash' shenanigans - simply use one of these, and wrap the commands for increasing/decreasing the backlight each with a simple script which you then reference in your udev rule.
Providing extra arguments is not necessary here, since you already have 'ATTR{online}==' as the differentiating factor...
Example:
udev rule:
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/innerpeace/.Xauthority", RUN+="/usr/local/bin/dec-backlight.sh"
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/innerpeace/.Xauthority", RUN+="/usr/local/bin/inc-backlight.sh"
dec-backlight.sh using the light utility:
#!/usr/bin/env bash
light -S 50
inc-backlight.sh, resepectively:
#!/usr/bin/env bash
light -S 80
Reason for editing: utitily > utility
Last edited by dogknowsnx (2022-08-16 11:56:36)
Notifications for Arch Linux package updates
RI - Rest your Eyes and Self
"We are eternal, all this pain is an illusion" - Maynard James Keenan
Offline
You'll be far better off using something closer to your current script than the tools linked above as many of those require a X11 display connection which you will not have with a udev-executed script. Those that don't require this will end up just doing what your script does, but they'll have a whole bunch of gymnastics around it which just opens up more potential for errors.
But yes, sudo is complete nonsense in this context, both in the command line given to udev and in the shebang of the script; remove both of those. The udev rule also does not need any DISPLAY or XAUTHORITY environment variables as nothing in your script requires an X11 display connection (which is best). You can also just put the value as the parameter to the script and the script itself can be just one line:
#!/bin/sh
echo ${1:-454} > /sys/class/backlight/intel_backlight/brightness
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Thank you! dogknowsnx, you are right but I prefer the way of Trilby, it worked perfectly! Thank Trilby.
Last edited by innerpeace (2022-08-15 12:28:20)
Offline
Please remember to mark your thread [SOLVED] (edit the title of your first post).
How to post. A sincere effort to use modest and proper language and grammar is a sign of respect toward the community.
Offline