Screensaver

If you need to disable the screen saver / screen auto switch off see here.

Auto Running The GUI

You can use the raspbian preferences via the GUI to cause the pi user to be auto logged in at boot up and the GUI automatically run.  However if you need to run with root privileges due to needing IO pin control (yes yes its not advised to run as root, but for many uses its fine where the security issues aren't a concern) then set the raspbian preferences to boot to the command line.  Now open this file (the "sudo nano" assumes you are editing it from the command line):


sudo nano /etc/rc.local

Before the "exit 0" line in it add the following line:


#Auto run the GUI as root
sudo startx

Save it by pressing Ctrl+X, " Y", ENTER

Re-boot your RPi and it should automatically run the GUI as the root user.  

"No session for pid 696"

We get this message when using this method, the number will be random based on system.  It may well be because of using sudo startx.

You can use command "ps 696"  to see the process there is no session for, for us it was:

  PID TTY      STAT   TIME COMMAND
  902 ?        Sl     0:00 lxpolkit

lxpolkit is a "Policy authentication agent".  There's lots of google resources on no session for PID with lxpolkit but after a few hours of trying we didn't manage to resolve.  Instead we started our application using a script with a delay before it runs so that it simply appears on top of the error message.  Bodge, but it works for us…

Setting An Application / Your Application To Automatically Run In The GUI

For the standard Pi user (if not using "sudo startx"):


sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

For the root Pi user (if running the GUI with "sudo startx"):


sudo nano /root/.config/lxsession/LXDE-pi/autostart

If the above gives a blank file, then there is not a per user file so edit the global one:


sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

This is the same file that is edited if you are disabling the screen saver, it causes things to be done when the GUI loads for a user. To run an application you simply add it on a line starting with a '@' character.  A good way to test it works is to run one of the built in applications, say LX Terminal, by adding the following:


@lxterminal

Use CTRL+X to save the file and then restart the GUI, you should see that LX Terminal is opened as soon as the GUI loads.

To run your own application then simply give the path to the executable file, which in this example is called "myapp":


@/home/pi/projects/myfolder/myapp
To run with a delay before launch

To run with a delay before your app launches, instead of adding the path to your app, provide a path to a script we will create:


@sh /home/pi/myapp_start.sh

Exit and save, then create the script file:


sudo nano /home/pi/myapp_start.sh

Insert the following into the file, setting the delay you want in seconds and the path to your app executable:


#!/usr/bin/sh
sleep 4
/home/pi/projects/myfolder/myapp

Exit and save, then finally make the script executable:


sudo chmod +x /home/pi/myapp_start.sh

Thats it, reboot and your app should launch after the delay period

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.