Run bash script as sudo with keyboard shortcut

Hi, i’m trying to update my screen brightness with a keyboard shortcut, so i wrote a script:

#!/bin/bash
echo 0 > /sys/class/backlight/intel_backlight/brightness

and i wrote the path of the script in a shortcut, but when i trigger it, nothing appen…
any idea?

Hi @Grainbox,

Your topic is:

Run bash script as sudo with keyboard shortcut

Yet, I see no mention of sudo. So I’m, thinking you want to run the script with sudo, but it doesn’t work.

Well, it could be that you need to add either the full path of the script to sudoers or you need to add the

echo 0 > /sys/class/backlight/intel_backlight/brightness

command to be able to be run with sudo without a password to sudoers, and change the script a bit:

#!/bin/bash
sudo echo 0 > /sys/class/backlight/intel_backlight/brightness

Honesly, I’d say the second option is better, because it wouldn’t allow the user created script to be run as root without a password, left to it’s own devices.

Edit:

Also have a look at:

https://unix.stackexchange.com/questions/501008/creating-shortcuts-profiles-in-xfce4

@Grainbox If not a bash script you can also install xorg-xbacklight package to manage screen brightness with keyboard shortcuts as it will work with intel. Also see Backlight - ArchWiki

xbacklight -inc 10 #to increase by 10%
xbacklight -dec 10 #to decrease by 10%
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.