Autostart ScratchGPIO projects

Sometimes it can be useful to make your Pi autorun something when it is switched on.

With ScratchGPIO, you can autorun a Scratch program (it doesn’t have to be one controlling the GPIO pins but ScratchGPIO is needed to make it autorun

There are 3 steps – create a launchscript, create a shortcut to it and finally create a Scratch script that autoruns its GreenFlag event on startup

Create Linux Script

Run LX Terminal

mkdir -p  /home/pi/.config/autostart


then type in following

cd /opt/scratchgpio8
sudo python &
scratch “/home/pi/Documents/Scratch Projects/”

CTRL-X then Y to save

chmod +x

Create shortcut to Launch the Script

Simply right-click on ScratchGPIO8 and select Open With then Text Editor

Then simple change the Exec and Name lines to:


Name=Scratch Auto Start

then save the modified desktop shortcut as:


Create a Scratch Autostart script

Make the Scratch script include the following in its On Green Flag Event


Then press the Green Flag to set AutoStart to True and save it as autostart in the normal /home/pi/Documents/Scratch Programs folder

Reboot your Pi and it should automatically run the Scratch file

Dealing with the Remote sensor connections pop-up

This information now superceded if using NuScratch – see

Old info left below as its still applies to all other Scratch 1.4 edidtions (PC/Mac/Intel Linux)

(Information from

There is one further issue which may or may not cause a problem with your script.

When ScratchGPIO runs, a pop-up message “Remote sensor connections enabled” appears and prevents Scratch from receiving keyboard events until it is dismissed.   This may or may not be an issue for you.  It it is then it needs to be turned off within the Scratch application, which is one of the hidden settings within Scratch.

After launching Scratch shift left-click on the R in the Scratch logo (top left) and choose “turn fill screen off”. Click on the white area to the right or bottom of the screen and choose “Open” and “Browser”. Navigate to the section Scratch-UI-Panes -> ScratchFrameMorph -> menu/button actions -> enableRemoteSensors and remove the line:

Dialogboxmorph Inform: 'Remote Sensor Connections Enabled' Localized

This can be seen in the screen shot below.

Disable Remote sensor connection enabled message in Scratch

Then click with the centre mouse button (or Ctrl and left button) and choose Accept (s).

You can now remove the white space in Scratch by shift left click on the R in Scratch logo and choose Turn Fill screen on. Finally shift left click on the logo again and choose “save image for end-user”