Script to generate your own names for sketches

Hello, I am unsure whether this should be posted here or in the Processing category, but here we go.


Starting with Processing 4, the names for new sketches can be made to follow a custom scheme. In that link it is explained how to do it, but there is no script or program that aids in creating the json file (that I know of, at least).

Until now; now you have a means to do it. Behold of my (almost) POSIX-compliant shell script to generate a custom naming scheme for new sketches in Processing :nerd_face:.

processing-naming.sh
#!/bin/sh
##
##This script combines two files to generate a naming scheme for new Processing
##sketches.
##
##Usage (redirects output to file "naming.json")
##  ./processing-naming.sh <prefixes-file> <suffixes-file> > naming.json
##
##It takes two arguments, then generates a json file to the standard output,
##which should be redirected to a file named "naming.json", as shown above.
##Then (See https://github.com/processing/processing4/wiki/Naming-Sketches)
## 1. Place the file "naming.json" in your sketchbook.
## 2. Change the value of the "names" and "notes" keys in "naming.json"
##   to your taste.
## 3. The new naming scheme is available from the preferences frame
##   in Processing.
##
##May you want to modify this script, but know little about shell scripting?
##you can use the following parser to aid you.
##https://www.shellcheck.net/
##
##TODO:
## - Combine multiple naming schemes (json files generated with this script)
##  into one single json file. Probably better with another script, to avoid
##  overloading this one.



##--------------------------------
##Function definitions
##--------------------------------

#DESC:
# Read every line from a file and write it to standard output,
# surrounded by quotes ("), with given indentation.
#USAGE:
#  process_afixes <file-to-read> <indentation>
#ARGS:
# <file-to-read>: file to read lines (suffixes and prefixes) from
# <indentation>: string with the indentation for each line in output
process_afixes () {
  #Check arguments
  if [ $# -ne 2 ] || [ ! -r "$1" ]; then
    printf 'Error: process_afixes: bad arguments\n'
    exit 1
  fi
  
  local FILE="$1" INDENT="$2"
  
  #Make the read command read until newline character
  local OLD_IFS="$IFS"
  IFS=""

  #For each line, check whether there is a next line
  #so that we can properly format the output
  local PREV_LINE=""
  while read -r line || [ -n "$line" ]; do
    if [ -n "$PREV_LINE" ]; then
      printf '%s"%s"' "$INDENT" "$PREV_LINE"
      #Next line is not empty (it may be if file ends with an empty line)
      if [ -n "$line" ]; then
        printf ','
      fi
      printf '\n'
    fi

    PREV_LINE="$line"
  done < "$FILE"
  
  #Write last line, if not empty
  if [ -n "$PREV_LINE" ]; then
    printf '%s"%s"\n' "$INDENT" "$PREV_LINE"
  fi

  #Reset the IFS variable to its previous state
  IFS="$OLD_IFS"
}

##--------------------------------
##End of function definitions
##--------------------------------




##--------------------------------
##Begin program
##--------------------------------

##Check two arguments are supplied
if [ $# -ne 2 ]; then
  printf 'Usage:\n  %s prefix-file suffix-file\n' "$0"
  exit 1
fi


##Check that both files exist and are readable
PREFIX_FILE="$1"
SUFFIX_FILE="$2"

if [ ! -e "$PREFIX_FILE" ] || [ ! -e "$SUFFIX_FILE" ]
   [ ! -r "$PREFIX_FILE" ] || [ ! -r "$SUFFIX_FILE" ]; then
  echo 'At least one of the arguments either does not exist'
  echo 'or is not readable by you'
  exit 2
fi


##Generate the output in json format

#Indentation for prefixes/suffixes of the json file
INDENT_VALUES='      '

#Beginning of json file
printf \
'[
  {
    "name": "My new custom naming scheme",
    "notes": "A super awesome custom naming scheme to brag about",
'

#Prefix key and values
printf \
'    "prefixes": [
'
process_afixes "$PREFIX_FILE" "$INDENT_VALUES"
printf '    ],\n'

#Suffix key and values
printf \
'    "suffixes": [
'
process_afixes "$SUFFIX_FILE" "$INDENT_VALUES"
printf '    ]\n'

#End of the json file
printf \
'  }
]
'

Will it work on my OS?

It will work on any POSIX-compliant shell, i.e. GNU/Linux and MacOS for sure.

For Windows users, you can use the Powershell, once you have installed WSL (Windows Subsystem for Linux). But there may be other ways.

How to use it

  1. Copy the shell script and save it to a file named processing-naming.sh (or whatever you feel like).
  2. Make it executable by issuing this command in the terminal chmod u+x processing-naming.sh.
  3. Save a list of prefixes to a file named prefixes.txt (or whatever), in one line each.
  4. Save a list of suffixes to a file suffixes.txt (or whatever), in one line each.
  5. Run the script ./processing-naming.sh prefixes.txt suffixes.txt. If you don’t see any errors, then
  6. Run the script storing the output to a file ./processing-naming.sh prefixes.txt suffixes.txt > naming.json.
  7. Change the name and notes values in the naming.json file to meet your taste.
  8. Place naming.json in your sketchbook folder and execute Processing. From the preferences window, choose your new custom naming scheme for new sketches.

The name naming.json is mandatory, not an option; otherwise Processing will ignore it.

Example

I have come up with this script to make my own custom naming scheme, based on a narrow set of programming languages. Here you have it, in case anyone is interested.

programming-languages
Ada
ALGOL
Assembly
Bash
BASIC
C
C#
C++
Carbon
COBOL
Erlang
Fortran
Gambas
GCode
Go
Haskell
Java
Javascript
Julia
Kotlin
Lisp
Logo
Lua
MATLAB
ObjectiveC
P5js
Pascal
Perl
PHP
Processing
Prolog
Python
R
Ruby
Rust
S
Scala
Scheme
Shell
Smalltalk
SQL
Swift
Tcl
Typescript
Vala
adjectives
amazing
astonishing
awful
bizarre
broken
dead
fantastic
fcked up
horrible
magnific
nightmare
outstanding
overwhelming
please no
scary
superior
terrible
ugly
unbeatable
unmatched
weird
wonderful

Together yielding

naming.json
[
  {
    "name": "Programming languages",
    "notes": "A list of programming languages and adjectives to qualify them",
    "prefixes": [
      "Ada",
      "ALGOL",
      "Assembly",
      "Bash",
      "BASIC",
      "C",
      "C#",
      "C++",
      "Carbon",
      "COBOL",
      "Erlang",
      "Fortran",
      "Gambas",
      "GCode",
      "Go",
      "Haskell",
      "Java",
      "Javascript",
      "Julia",
      "Kotlin",
      "Lisp",
      "Logo",
      "Lua",
      "MATLAB",
      "ObjectiveC",
      "P5js",
      "Pascal",
      "Perl",
      "PHP",
      "Processing",
      "Prolog",
      "Python",
      "R",
      "Ruby",
      "Rust",
      "S",
      "Scala",
      "Scheme",
      "Shell",
      "Smalltalk",
      "SQL",
      "Swift",
      "Tcl",
      "Typescript",
      "Vala"
    ],
    "suffixes": [
      "amazing",
      "astonishing",
      "awful",
      "bizarre",
      "broken",
      "dead",
      "fantastic",
      "fcked up",
      "horrible",
      "magnific",
      "nightmare",
      "outstanding",
      "overwhelming",
      "please no",
      "scary",
      "superior",
      "terrible",
      "ugly",
      "unbeatable",
      "unmatched",
      "weird",
      "wonderful"
    ]
  }
]

Here you have an image with 20 processing sketches

I agree with some of the names, I must say :grin:

Avoiding repetitions

Names are made up of prefixes and suffixes. If P is the amount of prefixes and S is the amount of suffixes, then N = P·S. You may want N to be large enough to prevent the same names appearing often.

This is actually the birthday problem in disguise, with names and sketches in place of birthdays and people. Since this is not a math class, I am just pointing out that my example has N = 45·22 = 990, so some 38 new sketches need to be opened up, in order to have a chance of 0.5 (i.e. 50%) of having at least two of them named the same.

Share your own

Nothing will make me happier than see others use my work to create their own custom naming schemes. Share them in the replies, if you want.

Have a good day.

3 Likes