2

The source for a program that automatically scales my laptop's keyboard brightness to its screen's brightness is given on the Arch wiki page for my laptop. I can compile it and when I run the program as root it works fine. Unfortunately, I do not know how to run this program every time I start my computer, and further the wiki states that I have to run it after I start the X server.

Since I'm using Arch, I imagine I have to do something with systemd, but I have no idea what. Any help would be greatly appreciated.

If it's relevant, the source is posted here.

  • What desktop environment are you using? The exact answer will differ depending on how X is launched, and which DE is being run (if any). – Chris Down Dec 20 '13 at 7:53
  • Unless you have systemd user sessions setup, you are probably better off running it from .xinitrc or your your WM/DE's autostart file. – jasonwryan Dec 20 '13 at 7:54
  • I'm running Gnome 3. Sorry, I should have included that in the question. – Anthony Brice Dec 20 '13 at 8:07
  • @AnthonyBrice I added information about doing this with GNOME 3 to my answer. – Chris Down Dec 20 '13 at 8:17
5

If you need to run it after the X server is started, it's probably more appropriate to start it using your desktop environment's settings, rather than attempting to cobble up something with systemd (although you could launch it with systemd in user session mode, but including your X launch in there may take some more work that would only be tangential to your goal, depending on how complex your setup is).

If you're using startx/xinit, just add the program to ~/.xinitrc, backgrounded:

/path/to/program &

Otherwise, find your startup settings in your desktop environment, and add the program there, so that it launches shortly afterwards.

Since it is now clear that you are running GNOME 3, you can run gnome-session-properties from Alt+F2, and add the program to the startup list there.

As the program needs superuser permissions to function, you need some way of elevating without being prompted for a password. To do this without blocking at the prompt, you can make your user able to run it with NOPASSWD in /etc/sudoers. Edit the file with sudo visudo, and add the following line at the bottom, edited as appropriate:

youruser ALL=NOPASSWD: /path/to/program

You can then run the program using sudo without being prompted for a password.

  • that's user specific, and the X server starts before the user even logs in – Thorsten Staerk Dec 20 '13 at 7:55
  • @ThorstenStaerk In many cases, the X server does not have to start before a user logs in. If you run a DM, it probably launches before the user logging in is logged in, but it does not have to be that way (startx/xinit is still popular, for one, I use it). But yes, it is user specific -- without information on the DE/DM at work here, that's about as good as it gets. – Chris Down Dec 20 '13 at 7:56
  • @ChrisDown I believe I have a problem in that I need the program to run with elevated permissions. If I include sudo /path/to/program in gnome-session-properties won't it hang at the prompt asking for my password? – Anthony Brice Dec 20 '13 at 8:18
  • @AnthonyBrice Sorry, I didn't notice that that was a requirement. I have added the steps to solve this at the end of my answer. – Chris Down Dec 20 '13 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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