Autostart a Processing sketch on the Raspberry Pi

This hasn’t been any where near as straightforward as I’d hoped, so here are some of the steps I’ve taken to try and make it happen.

The first problem is that Processing needs an window environment to operate, which means that it won’t run on a Pi which has no screen or keyboard attached. There is a hack for this, that fools Processing into thinking it has actual windows to work with. As recommended at this site (, install matchbox-window-manager:

The steps, to paraphrase, are:

Next, we need to get the Pi to automatically log in to a user. I’m using the default user here, and so followed the first part of the instructions at this site:

I quote:

Auto login to the Pi:

The first thing to solve is how to get the RPi to auto-login, thus removing the necessity of a connecetd keyboard & monitor (or ssh) to get things running.  This doc completely covers it:  But to paraphrase, this is what you need to do:

Edit /etc/inittab , the  file that controls the startup \ initialization process of the Pi.  Do a “What is /etc/inittab” in Google for a far more robust answer on the specifics of what it does.

In that file, comment out this line:

Like so:

And place this line under it:

Replacing “pi” with the user you want auto-logged on on power-up.  Reboot the Pi, and watch it auto-login.  Magic.

Next we need to make a script to set up the phony window environment and open our Processing app. I’ve exported my app from the Processing environment already, and it’s saved in my home folder. You can copy and paste the path to your own app into these instructions.

So, to make the script (called script_auto_run), we follow these instructions from this web page:

Create a folder to store the script in

Create the script using the nano text editor

In the nano editor, type this script:

Note that when executing a command without logging is as a user you can’t depend on any path or environment variables so you must provide full paths to everything. This is important, as any paths to external data files in your Processing sketch need to be absolute.

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

This script needs to be made executable by typing this :

Test it in terminal:

And for me, this works!


Now to get it to run on startup. Instructions now are from this site:

Using sudo nano, make a script called

in the /home/pi/bin/ folder (or, anywhere, I think). The code for this is here:

We then make this new script_autostart executable

Then we set this script to start up on boot. Instructions here are from

Setting it to be run

To launch the script at start-up edit the “rc.local” file needs to be edited.

Amend to say the following:

So, on startup, the Pi automatically logs in, then script_autostart gets called which initiates the window environment and starts up our app.

Considering I’m a complete and utter Pi newb, this feels like a significant victory! Thanks so much to the various authors of the instructions I followed – I’m very grateful for your help!