Plugin: space.sh

This is a special-purpose plugin designed to work with space components. Its job is to change the appearance of a space item to indicate whether it is currently active.

Usage

This script is assigned to each space item you create. SketchyBar automatically runs this script for all space items whenever the active space changes.

# From the default sketchybarrc
sketchybar --add space space.1 left \
           --set space.1 \
                 space=1 \
                 script="$PLUGIN_DIR/space.sh"

Source Code

#!/bin/sh

# The $SELECTED variable is available for space components and indicates if
# the space invoking this script (with name: $NAME) is currently selected:
# https://felixkratz.github.io/SketchyBar/config/components#space----associate-mission-control-spaces-with-an-item

sketchybar --set "$NAME" background.drawing="$SELECTED"

Explanation

  1. $SELECTED: This is a special environment variable provided only for scripts attached to space components. SketchyBar sets its value to true if the space is the active one on its display, and false otherwise.
  2. sketchybar --set "$NAME" background.drawing="$SELECTED": The script uses the value of $SELECTED to directly set the background.drawing property. This elegantly toggles the background visibility, highlighting the active space. For this to work, the space item must have a background color configured in the sketchybarrc file.