Skip to content

Add AEROSPACE_EMPTY_WORKSPACES env var to exec-on-workspace-change #430

Description

@karamanliev

Adding AEROSPACE_EMPTY_WORKSPACES to the exec-on-workspace-change event will make it possible to dynamically show/hide or visually indicate which workspace has no windows currently in it in sketchybar or similar softwares.

Example from the AeroSpace Goodness section in the readme:
aerospace.toml

exec-on-workspace-change = ['/bin/bash', '-c',
    '/opt/homebrew/opt/sketchybar/bin/sketchybar --trigger aerospace_workspace_change FOCUSED_WORKSPACE=$AEROSPACE_FOCUSED_WORKSPACE EMPTY_WORKSPACES=$AEROSPACE_EMPTY_WORKSPACES'
]

.config/sketchybar/plugins/aerospace.sh

#!/usr/bin/env bash

# make sure it's executable with:
# chmod +x ~/.config/sketchybar/plugins/aerospace.sh

#!/usr/bin/env bash

# make sure it's executable with:
# chmod +x ~/.config/sketchybar/plugins/aerospace.sh

if echo "$EMPTY_WORKSPACES" | grep -q "$1"; then
	LABEL_COLOR="$RED" # marks empty workspaces in red
else
	LABEL_COLOR="$WHITE" # marks workspaces with windows in white
fi

if [ "$1" = "$FOCUSED_WORKSPACE" ]; then
    sketchybar --set $NAME background.drawing=on label.color="$LABEL_COLOR"
else
    sketchybar --set $NAME background.drawing=off label.color="$LABEL_COLOR"
fi

Currently, if adding EMPTY_WORKSPACES=$(aerospace list-workspaces --monitor focused --empty) to ~/.config/sketchybar/plugins/aerospace.sh it is slow, because it computes it for every workspace on workspace change, which is not ideal and the performance drop is visible. I could not find other way to do it dynamically so it updates if the workspace becomes empty/popuplated. I've red to readmes many times, looked at other configs in github for a way to do it with no luck.

Checklist

aerospace CLI client version: 0.14.2-Beta 0cb8dbdfc5ee73b8cbc200f175f467ebead55201
AeroSpace.app server version: 0.14.1-Beta 5861e85b65cb7dc914a0a68027c56e2bc90510fd

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions