Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a script that I run every time I boot up my laptop (to reset the screen brightness). I would like to be able to execute this command using a Launcher:

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

Unfortunately, in order to execute this command (to edit the file) I need to be SU and type in my username and password. I know that UNIX shell scripts are designed such that you can't enter interactive variables like this, but I was hoping the Launcher would have more functionality.

Is it possible to enter interactive arguments like superusername and password in the Launcher? If so, how?

share|improve this question
    
You can try adding a NOPASSWD entry to /etc/sudoers with visudo to make it run without a password. –  hexafraction Aug 21 '12 at 19:42
add comment

1 Answer

up vote 5 down vote accepted

You can do this using gksu. Specifically make the launcher run the command:

gksu "bash -c 'echo 1500 > /sys/class/backlight/intel_backlight/brightness'"

This will make the script prompt you for your password and then change the brightness.

Another, better, solution that might or might not work depending on your hardware is to use the gnome-settings Daemon to change brightness. This will allow you to change brightness without needing to enter your password.

The command to do it this way is:

gdbus call --session --dest org.gnome.SettingsDaemon --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.SetPercentage 100

You can replace the 100 at the end with any percentage brightness from 0-100.

As I said this might not work in all cases and should only be used when you are logged in.

In order to get these to be runnable from the launcher you will need to make what is called a desktop file. To do this you should make a new file called ~/.local/share/applications/fullbright.desktop and copy paste the following into it.

[Desktop Entry]
Name=Full Brightness
GenericName=Brightness
Comment=Set Full Brightness
Exec=gdbus call --session --dest org.gnome.SettingsDaemon --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.SetPercentage 100
Terminal=false
Type=Application
Icon=checkbox
Categories=Utility;

If the gdbus command does not work on your system replace it with the gksu one.

You should now be able to call this command from the launcher with the name Full Brightness and pin it to your dock like any other program.

share|improve this answer
    
For some reason your first solution (the gksu solution) isn't working. It looks like it is working fine, but in the end the screen brightness isn't reset like it is if I just SUDO. Can you give me your method for writing this .desktop file? Thank you for your help. –  theJollySin Aug 22 '12 at 15:25
1  
@theJollySin Sorry. I made a mistake with the gksu command but I fixed it now. Really though you should use the gdbus one if possible. I have also added a desktop file for it. –  Alex L. Aug 22 '12 at 17:05
    
Thank you! That is a great solution (I went with the gksu method, my laptop has a high-end monitor and I couldn't get the Gnome settings working at all). This is still kind of an ugly work around for an Ubuntu problem, but I'm happy with the result. –  theJollySin Aug 23 '12 at 3:45
    
Thank you for this answer, I am very surprised to say that I have looked into this brightness issue about 5 different times and somehow never come across this post. (Changing brightness from the graphical menus and from the function keys do not work correctly on my laptop but this does). I think I will write a script and/or desktop launcher that makes it possible to increment/decrement brightness using this command - I'll post it here when I'm done. –  seafangs Nov 14 '12 at 15:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.