[sketchybar] only show aerospace items for connected monitors
diff --git a/.config/sketchybar/plugins/aerospace.sh b/.config/sketchybar/plugins/aerospace.sh
index 5fd8e7fb..15cec986 100755
--- a/.config/sketchybar/plugins/aerospace.sh
+++ b/.config/sketchybar/plugins/aerospace.sh
@@ -3,7 +3,6 @@
# Original source:
# https://nikitabobko.github.io/AeroSpace/goodness#show-aerospace-workspaces-in-sketchybar
-# Function to get focused workspace for a specific monitor
get_focused_workspace_for_monitor() {
local monitor_id=$1
@@ -21,30 +20,37 @@ get_focused_workspace_for_monitor() {
fi
}
-# Function to update a specific monitor's workspace
+is_monitor_connected() {
+ local monitor_id=$1
+ aerospace list-monitors 2>/dev/null | grep -q "^$monitor_id "
+}
+
update_monitor_workspace() {
local monitor_id=$1
local item_name="aerospace_$monitor_id"
+ # Hide the item if monitor is not connected
+ if ! is_monitor_connected $monitor_id; then
+ sketchybar --set $item_name drawing=off
+ return
+ fi
+
local workspace=$(get_focused_workspace_for_monitor $monitor_id)
if [ -n "$workspace" ]; then
+ # Show the item since monitor is connected
+ sketchybar --set $item_name drawing=on
+
local focused_workspace=$(aerospace list-workspaces --focused 2>/dev/null)
local monitor_count=$(aerospace list-monitors | wc -l)
- # Only highlight if there are multiple monitors
+ # Highlight the focused workspace if there are multiple monitors
if [ "$monitor_count" -gt 1 ] && [ "$workspace" = "$focused_workspace" ]; then
- # Highlight the focused workspace
sketchybar --set $item_name \
label="$workspace" \
background.drawing=on \
- label.padding_left=8 \
- label.padding_right=8 \
- padding_left=3 \
- padding_right=3 \
label.color=0xff000000
else
- # Normal appearance for non-focused workspaces or single monitor
sketchybar --set $item_name \
label="$workspace" \
background.drawing=off \
@@ -60,7 +66,6 @@ if [ -n "$NAME" ]; then
update_monitor_workspace $monitor_id
else
# Update all monitors
- # Get list of monitors and update each one
aerospace list-monitors | while IFS= read -r monitor; do
monitor_id=$(echo "$monitor" | awk '{print $1}')
update_monitor_workspace $monitor_id
diff --git a/.config/sketchybar/sketchybarrc b/.config/sketchybar/sketchybarrc
index 491e472c..6d2bdfe1 100755
--- a/.config/sketchybar/sketchybarrc
+++ b/.config/sketchybar/sketchybarrc
@@ -55,6 +55,10 @@ if command -v aerospace >/dev/null 2>&1; then
background.border_color=0xffcccccc \
background.corner_radius=6 \
background.height=26 \
+ label.padding_left=8 \
+ label.padding_right=8 \
+ padding_left=3 \
+ padding_right=3 \
script="$CONFIG_DIR/plugins/aerospace.sh"
done
fi