Executing Sketch via Linux Command Line?

If you want to have a bunch of sketches in the same folder and be able to run them, you could use a bash script for launching them. Lets assume we have these files and folders somewhere on our computer:

$ ls
data/
runp5.sh
test1.pde
test2.pde

The data folder can contain images, sounds etc needed by your sketches.

I have two working sketches (test1 and test2) and then my launcher script runp5.sh that looks like this:

#!/bin/bash

# The argument with .pde removed
base=${1%.pde}

# The folder where we will store the sketch
p5path="/tmp/$base"

# Remove the folder if it exists...
rm -rf $p5path

# ...and create it again
mkdir $p5path

# Symlink the data folder
ln -s "$(realpath data)" $p5path/data

# Symlink the pde file
ln -s "$(realpath $1)" $p5path/$1

# Run!
processing-java --sketch=$p5path --run

This script must be executable (you can do chmod +x runp5.sh)

Once things are set up like this, you can launch the sketches like this:

./runp5 test1.pde
./runp5 test2.pde

What does it do? basically it creates the required folder structure to run the sketch by using symbolic links, which is nice because they are tiny so it’s not copying any huge files you may have in data. Also nice because if you edit the files inside /tmp (say with the Processing IDE) changes are reflected in their original location.

But… it won’t work if your sketch uses multiple pde files, or in other cases I haven’t thought of.

1 Like