Running a command on boot

One key technical skill for building creative embedded devices is to be able to start a program on boot. This will allow non-technical users to plug in your device, and immediately begin consuming your art.

The basic premise of starting a program on system boot is to insert the program invocation into a script that the OS runs on startup. On the Raspbian Linux distribution (which is likely on your Raspberry Pi), this file is located at ~/.config/lxsession/LXDE-pi/autostart or /etc/rc.local.

Sonic Pi

In order to start a Sonic Pi program when your device boots, we can use the Sonic Pi start up file, located at ~/.sonic-pi/init.rb. This file will be executed every time Sonic Pi is started - by then automatically running Sonic Pi on boot through, for example the startup file list above, you can always start your system on device boot.

Another approach is to use the sonic-pi-tool.

Processing

Add a line /usr/local/bin/processing-java --sketch=/home/pi/sketchbook/sketchname --run to your startup script file.

Running a command on device connect

You may also want to run a command automatically when a device (eg a usb) is plugged in. One way to do this is with udev rules. You can make a new udev rule by adding a file under the /etc/udev/rules.d/ directory.