Search code examples
bashdebiansudo

Running a script asking for sudo permission from a keyboard shortcut xfce4


I have written a small script which basically change brightness of screen because keyboard shortcuts for brightness are not working. the bash script is as follows: #!/bin/bash echo $1 | sudo tee /sys/class/backlight/apple_backlight/brightness and I added this line in sudoers file to prevent asking for password: kareem dhcppc2 = /home/kareem/bin/backlight.sh However this line seems wrong as it does ask for password.

After adding the command as a keyboard shortcut, pressing the shortcut doesn't make any response.

I know this seems to be a noob question, I am a bigger in writing scripting.


Solution

  • Forgive me if I'm wrong, but you seem to need to automatically enter your password for sudo...I wouldn't advise this, as it requires that you write your password in plain text, but... I would use expect for this one...

    spawn /home/kareem/bin/backlight.sh
    expect "Password:"
    send "$pass\n"
    

    Hope that works...If it doesn't, just google how to use expect in bash.