The sketchybarrc
Configuration File
All of SketchyBar's configuration is managed through a single executable file, sketchybarrc
. This file is simply a shell script that runs a series of sketchybar
commands to set up your bar, its items, and their properties.
Location
By default, SketchyBar looks for the configuration file at the following location:
~/.config/sketchybar/sketchybarrc
You can also specify a different configuration file at launch time using the --config
or -c
flag:
sketchybar --config /path/to/my/custom_config
Structure
The sketchybarrc
file is executed from top to bottom. It typically follows this structure:
- Global Bar Settings: Define the bar's position, height, color, etc., using
sketchybar --bar ...
. - Default Item Settings: Set default properties for all subsequent items using
sketchybar --default ...
to avoid repetition. - Item Creation: Add all your desired items (
--add item
,--add space
, etc.) and set their specific properties (--set <name> ...
). - Event Subscriptions: Subscribe items to events so they can update dynamically (
--subscribe <name> <event>
).
See the Quick Start guide for a detailed walkthrough of the default sketchybarrc
.
Execution and Permissions
SketchyBar executes this file directly. Therefore, the sketchybarrc
file must have execute permissions.
chmod +x ~/.config/sketchybar/sketchybarrc
Environment Variables in Scripts
When SketchyBar runs a script associated with an item (via the script
or click_script
property), it provides several helpful environment variables.
-
$NAME
: The name of the item that triggered the script. This is crucial for updating the correct item from within the script.# In a script, update the label of the item that ran it sketchybar --set "$NAME" label="New Value"
-
$SENDER
: The name of the event that triggered the script. This can be a system event likevolume_change
, a custom event, or special values likeroutine
(forupdate_freq
triggers) andforced
(for manual triggers). -
$INFO
: Contains event-specific information. For example, for thefront_app_switched
event,$INFO
will contain the name of the new frontmost application. -
$SELECTED
: This is specific tospace
components. It will betrue
if the space is currently active on its display, andfalse
otherwise. -
$CONFIG_DIR
: An absolute path to the directory containing yoursketchybarrc
file (e.g.,~/.config/sketchybar
). This is useful for reliably locating plugin scripts. The default configuration uses this to define aPLUGIN_DIR
variable:PLUGIN_DIR="$CONFIG_DIR/plugins" sketchybar --set my_item script="$PLUGIN_DIR/my_script.sh"