Invoking Processor IDE from command line

I am running Processing on Raspberry Pi 3. I work mainly one one rather long sketch. It would be handy to invoke the IDE editor from the command line so I do not have to start Processing to a generic sketch then load mine as a second step and close the first window

I can start Processing IDE from the command line by

/usr/local/bin/processing

This works but still gets me to an empty sketch. I would like to supply the file path to my sketch but haven’t found any way to do it.
I can run the sketch without the IDE by:

/usr/bin/processing-java --sketch=filePath --run

Utilmately I would like to put an icon on the desktop to start the editor with my sketch.

Hi @rhole,

Welcome to the forum! :wink:

If you print out the processing shell script, you have:

#!/bin/sh

# This script runs Processing, using the JRE in the Processing 
# installation directory.

# If your system needs a different version of Java than what's included
# in the download, replace the 'java' folder with the contents of a new
# Oracle JRE (Java 8 only), or create a symlink named "java" in the 
# Processing installation directory that points to the JRE home directory.
# This must be a Sun/Oracle JDK. For more details, see here:
# https://github.com/processing/processing/wiki/Supported-Platforms

# Thanks to Ferdinand Kasper for this build script. [fry]


# JARs required from JDK (anywhere in/below the JDK home directory)
JDKLIBS="rt.jar"

# Set this to non-zero for logging
LOGGING=0

# Logs name and value of a variable to stdout if LOGGING is non-zero.
# Expects the variable name as parameter $1.
log() {
  if [ $LOGGING -ne 0 ]; then
    eval echo $1=\$$1
  fi
}


# Locates JDKLIBS in a directory and its subdirectories and saves their
# absolute paths as list to JDKCP. Expects the directory as parameter $1.
# Sets SUCCESS to 1 if all libraries were found, to 0 otherwise.
make_jdkcp() {
  # Back out of JRE directory if apparently located inside a JDK
  if [ -f "$1/../bin/java" ]; then
    DIR="$1/.."
  else
    DIR="$1"
  fi
  log DIR

  JDKCP=
  SUCCESS=1

  # Locate JDKLIBS
  for L in $JDKLIBS; do
    # Locate only the first library with a matching name
    LIB=`find "$DIR" -name $L 2>/dev/null | head -n 1`
    log L
    log LIB

    # Library found?
    if [ -n "$LIB" ]; then
      JDKCP="$JDKCP"${JDKCP:+:}"$LIB"
    else
      SUCCESS=0
    fi
  done

  log JDKCP
}


# Get absolute path of directory where this script is located
APPDIR=`readlink -f "$0"`
APPDIR=`dirname "$APPDIR"`
log APPDIR

# Try using a local JDK from the same directory as this script
JDKDIR=`readlink -f "$APPDIR/java"`
make_jdkcp "$JDKDIR"
log SUCCESS

# Don't use the installed JDK, because it's not supported.
# Local JDK found?
#if [ $SUCCESS -ne 1 ]; then
#  # No, try using the preferred system JRE/JDK (if any)
#  JDKDIR=`which java` && JDKDIR=`readlink -e "$JDKDIR"` && JDKDIR=`dirname "$JDKDIR"`/..
#  make_jdkcp "$JDKDIR"
#  log SUCCESS
#fi

# Add all required JARs to CLASSPATH
CLASSPATH="$CLASSPATH"${CLASSPATH:+:}"$JDKCP"
for LIB in "$APPDIR"/lib/*.jar; do
  CLASSPATH="$CLASSPATH"${CLASSPATH:+:}"$LIB"
done
for LIB in "$APPDIR"/core/library/*.jar; do
  CLASSPATH="$CLASSPATH"${CLASSPATH:+:}"$LIB"
done
for LIB in "$APPDIR"/modes/java/mode/*.jar; do
  CLASSPATH="$CLASSPATH"${CLASSPATH:+:}"$LIB"
done
export CLASSPATH
log CLASSPATH

# Make all JDK binaries available in PATH
export PATH="$JDKDIR/bin":"$PATH"
log PATH

current_name=`basename $0`
cmd_name='processing-java'

if [ $current_name = $cmd_name ]
then
    java -Djna.nosys=true -Djava.ext.dirs="$APPDIR"/java/lib/ext -Xmx256m processing.mode.java.Commander "$@"
    exit $?
else
  # Start Processing in the same directory as this script
  if [ "$1" ]; then
    SKETCH=`readlink -f "$1"`
  else
    SKETCH=
  fi
  cd "$APPDIR"

  java -splash:lib/about-1x.png -Djna.nosys=true -Djava.ext.dirs="$APPDIR"/java/lib/ext -Xmx256m processing.app.Base "$SKETCH" &
fi

The interesting part is at the end when invoking the IDE with the SKETCH variable:

# Start Processing in the same directory as this script
  if [ "$1" ]; then
    SKETCH=`readlink -f "$1"`
  else
    SKETCH=
  fi
  cd "$APPDIR"

  java -splash:lib/about-1x.png -Djna.nosys=true -Djava.ext.dirs="$APPDIR"/java/lib/ext -Xmx256m processing.app.Base "$SKETCH" &

It’s checking for $1 which is the second argument in the list of arguments and if it exists it assigns it to SKETCH with readlink (which resolves symbolic link or filenames to a path) which is then passed to processing.app.Base.

If you modify the script and print out the SKETCH variable with echo $SKETCH, you get the second argument as an absolute path:

$ processing sketch/sketch.pde
/absolute/path/to/sketch/sketch.pde

So you need to pass the path of your .pde file to the processing command in order to open the sketch with the IDE! :yum:

Thanks. I was SO close, I specified the sketch folder, not full path to the sketch .pde file. It works great now.
Now I will work of putting a desktop icon to automate the command line. That info should be readily available.

/usr/local/bin/processing /home/pi/sketchbook/xxx/xxx.pde
# where xxx is the name of the sketch to be editted
1 Like