Plugin: front_app.sh
This plugin is designed to display the name of the currently active application. It works by responding to the front_app_switched
event.
Usage
To use this plugin, you create an item and subscribe it to the front_app_switched
event.
sketchybar --add item front_app left \
--set front_app script="$PLUGIN_DIR/front_app.sh" \
--subscribe front_app front_app_switched
--subscribe front_app front_app_switched
: This is the key part. It tells SketchyBar to runfront_app.sh
only when the frontmost application changes. This is highly efficient.
Source Code
#!/bin/sh
# Some events send additional information specific to the event in the $INFO
# variable. E.g. the front_app_switched event sends the name of the newly
# focused application in the $INFO variable:
# https://felixkratz.github.io/SketchyBar/config/events#events-and-scripting
if [ "$SENDER" = "front_app_switched" ]; then
sketchybar --set "$NAME" label="$INFO"
fi
Explanation
if [ "$SENDER" = "front_app_switched" ]
: This check ensures the code only runs when triggered by the correct event. While this item is only subscribed to one event, this is good practice for scripts that might be subscribed to multiple events.$INFO
: For thefront_app_switched
event, SketchyBar automatically populates the$INFO
environment variable with the name of the new application.sketchybar --set "$NAME" label="$INFO"
: The script then takes the application name from$INFO
and sets it as the label for thefront_app
item.