-
|
I use Aerospace as my wm and want Sketchybar to display:
I wrote the following config., but I believe my subscriptions aren't working correctly. Every time e.g.lets say I already have non-empty ws "1 2 4" and now open ws 3 My Setup:aerospace.toml exec-on-workspace-change = [
'/bin/bash', '-c',
'sketchybar --trigger aerospace_workspace_change && sketchybar --trigger workspace_update'
]sketchybarrc ##### Adding Left Items #####
# Add Aerospace workspace event handler
sketchybar --add event aerospace_workspace_change
# Add workspace manager
sketchybar --add item workspace_manager left \
--set workspace_manager \
icon.padding_left=0 \
icon.padding_right=0 \
label.padding_left=0 \
label.padding_right=0 \
script="$PLUGIN_DIR/workspace_manager.sh" \
--subscribe workspace_manager aerospace_workspace_change
# here might be the problemworkspace_manager.sh #!/bin/bash
echo "workspace_manager.sh triggered"
# Get config directory
CONFIG_DIR="${CONFIG_DIR:-$HOME/.config/sketchybar}"
source "$CONFIG_DIR/colors.sh"
# Get workspace states
NON_EMPTY=($(/opt/homebrew/bin/aerospace list-workspaces --monitor focused --empty no))
FOCUSED=$(/opt/homebrew/bin/aerospace list-workspaces --focused)
# Combine workspaces to show (non-empty + focused)
WORKSPACES_TO_SHOW=($(echo "${NON_EMPTY[@]}"$'\n'"$FOCUSED" | sort -n))
# Get existing space items from SketchyBar
EXISTING=($(sketchybar --query bar | jq -r '.items[] | select(startswith("space."))'))
# Remove workspaces that shouldn't be shown
for existing in "${EXISTING[@]}"; do
sid=${existing#space.}
# check if workspace is empty and not focused
if [[ ! " ${WORKSPACES_TO_SHOW[@]} " =~ " ${sid} " ]]; then
sketchybar --remove "$existing"
fi
done
# Add/update workspaces that should be shown
for sid in "${WORKSPACES_TO_SHOW[@]}"; do
if ! sketchybar --query "space.$sid" &> /dev/null; then
if [ $sid = "11" ]; then
LABEL="magic"
#this is my equivalent to scratchpad in hyprland
else
LABEL="$sid"
fi
sketchybar --add item "space.$sid" left \
--set "space.$sid" \
background.color=0x44ffffff \
background.corner_radius=4 \
background.height=20 \
background.drawing=off \
label="$LABEL" \
click_script="/opt/homebrew/bin/aerospace workspace $sid" \
script="$CONFIG_DIR/plugins/space.sh $sid" \
update_freq=1 \
--subscribe "space.$sid" aerospace_workspace_change workspace_manager
# somewhere here should be the error
fi
done
# Force update
sketchybar --trigger workspace_updatespace.sh #!/bin/sh
# Get config directory
CONFIG_DIR="${CONFIG_DIR:-$HOME/.config/sketchybar}"
source "$CONFIG_DIR/colors.sh"
# Get workspace ID
if [ -n "$1" ]; then
WORKSPACE_ID="$1"
else
WORKSPACE_ID="${NAME#space.}"
fi
# Get focused workspace
FOCUSED=$(/opt/homebrew/bin/aerospace list-workspaces --focused)
# Highlight if focused
if [ "$WORKSPACE_ID" = "$FOCUSED" ]; then
sketchybar --set $NAME \
background.color=$MAUVE \
background.drawing=on \
background.y_offset=0 \
label.color=$CRUST
else
sketchybar --set $NAME \
background.drawing=off \
label.color=$TEXT
fiIssue Summary:
Does anyone know why the workspaces aren’t updating in the correct order? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
|
Lets say you have an ordered list of workspaces in 1: banana Then you remove the empty ones (lets say 3: Lemon) in the 1: banana then you iterate through the list of newly added workspaces since last update in the final section and then add them to the end. (lets say 7: melon): 1: banana lets say you keep doing this (remove banana next and re-add lemon, for instance) you next get: 2: orange etc,etc. You can achieve what you want by completely removing all items from SB and re-adding your ordered list in the last code block. Just remove the if guard: and then remove the if guard in the final block (it's redundant now as all tested items will not exist in SB as we removed them in the last step): I liked your idea, so borrowed it! There doesn't seem to be any performance hit to completely removing and re-adding the workspaces (at least none I can notice) and the goal of ordered workspaces is achieved. Hope it helps you or someone else! |
Beta Was this translation helpful? Give feedback.
-
|
But since I've written this, there IS a performance hit when clicking on workspace in SB - you get a noticeable re-draw. Which I didn't get last night, so it's fragile. When the systems under some other load then the redraw can become noticeable! I'm going to see if there's a better approach and report back - because I want this too! |
Beta Was this translation helpful? Give feedback.
-
|
ok, so keeping your if guards to only add/remove changed workspaces, then change: to: finally add: to the end of workspace manager script. et voila! (I also removed update_freq=1 as it was messing with my active workspace highlighting... ymmv depending on your set-up) my complete working set-up: some of my var names are different to yours (my service is called ws_manager_built_in.sh as it's for the built-in screen only) and I've adapted what I already had to map onto yours... but the name changes are superficial as it's mostly your script at this point! |
Beta Was this translation helpful? Give feedback.
-
|
But it only updates/reorders when I click on/key-bind to a new workspace, not when I close an app or send it to a new workspace.... will update when I've fixed that! |
Beta Was this translation helpful? Give feedback.
ok, so keeping your if guards to only add/remove changed workspaces, then change:
EXISTING=($(sketchybar --query bar | jq -r '.items[] | select(startswith("space."))'))to:
EXISTING=($(sketchybar --query bar | jq -r '.items[] | select(startswith("space."))' | sort -n))finally add:
to the end of workspace manager script. et voila!
(I also removed update_freq=1 as it was messing with my active workspace highlighting... ymmv depending on your set-up)
my complete working set-up: