Auto Start a Desktop Application on the Rapberry PI

In the article on ten things to do after after buying a Raspberry PI, item number 9 shows how to automatically start an application at boot time when booting to the command prompt. This blog article will now show how to auto start an application when booting into the desktop of the Raspbian operating system running on the PI. It also shows how to auto run a command line application or shell script in a terminal window on the desktop.

NOTE: This is one way to auto start applications, but not the only way. There are other methods to do the same thing.

Auto Starting a Raspberry PI Desktop Application

The Setup

Some folders (directories) and a file need to be created as described here. How to do this is explained below the description.

  1. First create a folder called lxsession in the hidden folder called .config in the home directory.
  2. Now create a folder called LXDE-pi (name the folder LXDE in older Raspbian versions) in the lxsession folder.
  3. Finally create a text file called autostart in the lxsession folder.

You should end up with:


Or on older Raspbian versions:


Starting the Application Automatically

To start the application automatically, edit the autostart text file that you created above and add the application name that you want to start preceded by the @ symbol. For example, to auto start the calculator application (called galculator) the contents of your autostart file would look like this:


The next time that you start the desktop, the calculator application will automatically start.

If you write your own application that does not appear in the Linux PATH, then you will need to specify the path to the application, e.g. for an application in the home directory:




How to Do the Setup from the Desktop

To do the above steps on the desktop, start the file manager and then press Ctrl + H to show the hidden files and folders. Double-click the .config folder to open it. Right-click in the folder and use the pop-up menu to create the lxsession folder. Open the lxsession folder, right-click again and create the LXDE-pi folder. Open the LXDE-pi folder, right-click again and create the autostart text file. Double-clicking the autostart file will open it in the text editor. Add your application name to the file and save — don’t forget the preceding @ symbol as described above. Press Ctrl + H again any time that you want to hide the hidden files and folders in the file manager (Hidden files and folders have a period or dot (.) in front of their names in Linux. Ctrl + H toggles between hiding and showing these files in the file manager).

How to Do the Setup from the Command Line

On the command line in the pi home directory, enter:

mkdir -p .config/lxsession/LXDE-pi
nano .config/lxsession/LXDE-pi/autostart

Now enter the application that you want to automatically start, then save the file and exit (don’t forget the preceding @ symbol), e.g.:


Save the file in nano:

Ctrl + o

Exit nano:

Ctrl + x

Auto Starting a Raspberry PI Command Line Application on the Desktop

To start a command line application in a terminal window on the desktop, you will need to do the above steps to auto start the terminal window called lxterminal. In the auto start file, add the following line:


To run a command line application in the terminal, it is necessary to use the same method that was used in the article ten things to do after after buying a Raspberry PI, item number 9. And that is…

Open the hidden file .bashrc found in the home directory and add the name of the application or script that you want to run. For example, to run the top command line application, the end of your .bashrc file will look like this:

# existing text in .bashrc file ...
    . /etc/bash_completion

This will run top in a terminal window the next time that you start the desktop.

To run a custom script in the terminal window on the desktop, insert the path to the script and the script name. E.g. for a script called found in the home directory:

# existing text in .bashrc file ...
    . /etc/bash_completion


Raspberry PI – Updating Raspbian Software Packages and Firmware

After installing the Raspbian operating system on a Raspberry PI board SD card, the firmware and Raspbian software should be upgraded to the latest versions.

Upgrades also need to be done from time to time to make sure that your PI software contains the latest bug fixes and improvements.

Upgrading the Firmware

The firmware upgrade updates the Broadcom firmware / bootloader software for the Raspberry PIs Broadcom processor chip (technically SoC — System on a Chip).

To upgrade the firmware, enter this command on the command line:

sudo rpi-update

You will then need to reboot the PI for the changes to be loaded:

sudo shutdown -r now

The firmware resides on the SD card with the operating system.

Upgrading the Software Packages

To upgrade the actual Raspbian operating system, first the list of updates must be obtained by running this command from the command line:

sudo apt-get update

Now the actual updates must be installed by running:

sudo apt-get upgrade

Further, if updates require new packages to be added or existing packages to be removed, the following command will do this:

sudo apt-get dist-upgrade

The dist-upgrade command will not update the software to the latest distribution but allows addition and removal of packages, whereas upgrade only upgrades packages to the newest version. Most of the time using just the apt-get upgrade command will be fine, however, see the resources below for a better understanding on when each one is needed.

The apt-get commands above apply to any Debian Linux based operating system, not just Raspbian. These commands can be used on Debian, Ubuntu desktop, Linux Mint, Ubuntu Server, etc.


The following resources describe the differences between apt-get upgrade and apt-get dist-upgrade better, as well as provide a reference for other apt-get commands.

  1. Differences between upgrade and dist-upgrade
  2. Updating from the command line
  3. Ubuntu apt-get howto

Raspberry PI – Black Borders and Blank Screen in Raspbian with HDMI Monitor

Every time that I set up my Raspberry PI with a new version of the Raspbian operating system, I seem to have to use different settings for the HDMI screen — even though I am using the same hardware every time. I am not sure if this has to do with installing Raspbian using NOOBS versus using the Raspbian image file.

When I wrote the article on 10 things to do after buying a Raspberry PI, I only needed to change the disable_overscan parameter to  disable_overscan=1 in the /boot/config.txt file to remove the black border on the screen.

I recently installed a new version of Raspbian (2015-02-16-raspbian-wheezy.img) directly from the image file i.e. not using NOOBS. Nothing would display on the screen — the screen was just black / blank. I did discover that if I powered up the screen first, waited a few seconds and then powered up the PI, that the PI boot up and login prompt then displayed on the screen, although with wide black borders. At least this allowed me to configure Raspbian using the default configuration screen that appears after first boot of a new Raspbian install.

Below are the steps that I had to take to fix the blank screen and black border problems on my Raspberry PI.

Fixing the Blank Screen Problem

You may need to change different settings for your screen, depending on which screen you are using. The following is what worked for me, but this will show you where you can start changing settings to see what works for you.

Booting Up

I had to switch the screen on first with the PI power off, wait a few seconds and then plug the PI power in. The screen now worked. If the PI and screen were ever switched on at the same time, the screen went blank, even though the PI booted up.

If you can’t get anything to display on your screen, you may need to remove the SD card and access it from a PC to make changes to the config.txt file.

Changing the Settings

The config.txt file needs to be modified to make changes to the screen configuration. This file is found in the /boot directory on the SD card which is a separate partition as well. If you plug the SD card into a Windows PC, you will be prompted to open the boot folder of the SD card and you will find config.txt in this folder which you can then modify. Linux desktop operating systems will usually open both the boot partition and the contents of the SD card in two separate file managers.

In my case, I could modify the config.txt file on the PI without the need of a PC. This can be done from the command line using the nano text editor. It can also be done from the graphical desktop. In both cases the file must be opened using super user privileges or modifications will not be able to be saved.

To open the config.txt file as super user using the nano text editor from the command line, enter:

sudo nano /boot/config.txt

To open the config.txt file as super user from the PI desktop:

  1. Press Alt + F2 to bring up the Run box.
  2. Enter gksudo pcmanfm in the run box and press enter or click OK. This opens the file manager with super user privileges.
  3. You can click Close in the dialog box that pops up.
  4. Navigate to the boot folder by clicking the boot partition in the left pane of the file manager.
  5. You can now open config.txt in the main pane of the file manager by double-clicking it.
  6. It is best to close the file manager now, as it has been opened with super user privileges and can be used to modify or delete other files from the file system.
  7. Changes can now be made to config.txt and saved.

With the config.txt file now open with super user privileges, we can fix the blank screen problem. The problem may be fixed by uncommenting (i.e. removing the # sign in front of) the following line:


NOOBS users be aware that the parameters that are changed usually appear at the top of the config.txt file commented out and then again at the bottom of the file uncommented. Make changes to the bottom uncommented parameters, unless you can’t find the parameter that you are looking for at the bottom of the file.

This did not solve the problem in my case. I had to do two things – uncomment the hdmi_force_hotplug line and uncomment and change the settings of hdmi_group and hdmi_mode.

Every time that a parameter is changed in config.txt, the system must be rebooted in order for the changes to be seen. You may need to change a parameter at a time and reboot to see the effect.

The settings that solved my problem are shown here:

# uncomment if hdmi display is not detected and composite is being output

# uncomment to force a specific HDMI mode (this will force VGA)

The hdmi_group and hdmi_mode settings are obtained from the video mode options on the RPiconfig page. You will need to scroll down a bit to see the options. The settings that I used above mean the following:

hdmi_group=1   # define screen resolution in CEA format
hdmi_mode=4    # 720p   60 Hz

Rebooting after changing these settings fixed the blank screen problem and I could now switch the screen and PI on at the same time.

Fixing the Black Border Problem

The black border can be removed and adjusted by changing parameters in the config.txt file again. Open the config.txt file as super user again as described above.

Reminder: NOOBS users be aware that the parameters that are changed usually appear at the top of the config.txt file commented out and then again at the bottom of the file uncommented. Make changes to the bottom uncommented parameters, unless you can’t find the parameter that you are looking for at the bottom of the file.

Now uncomment the disable_overscan parameter and set it to 1:


Reboot and see if the black borders have gone. If they are still there, you will need to adjust the size of the borders to remove them using the following parameters:


Increasing the number in these parameters decreases the size of the border.

With the above settings changed, my PI and screen were fully functional and looking good. Here is my complete config.txt file to for you to see all the changes together:

# For more options and information see 
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border

# uncomment to force a console size. By default it will be display's size minus
# overscan.

# uncomment if hdmi display is not detected and composite is being output

# uncomment to force a specific HDMI mode (this will force VGA)

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display

# uncomment for composite PAL

#uncomment to overclock the arm. 700 MHz is the default.

New Raspberry PI Model A+

The new Raspberry PI Model A+ board has been launched this month. It is a smaller version of the Model A and shares some of the features of the model B+. The board size is 56mm wide by 66mm long and 14mm high.

This video from RasPi.TV has more details on the new board:

The RasPi.TV blog has more details and photos of the new Raspberry PI board.