Question: Query the current mode/workspace #650
-
Hello, new Aerospace user here, love it so far! Is there a way to query (ideally from the CLI) the current mode/workspace? A bit like the tray display, I'd like to show this in my Sketchybar toolbar (not the native MacOS one). Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Take a look here: https://nikitabobko.github.io/AeroSpace/goodness#show-aerospace-workspaces-in-sketchybar I haven't updated my dotfiles yet but this is what I have so far: make sure to edit your aerospace config file with: # Notify Sketchybar about workspace change
exec-on-workspace-change = [
'/bin/bash',
'-c',
'sketchybar --trigger aerospace_workspace_change FOCUSED=$AEROSPACE_FOCUSED_WORKSPACE',
] items/aerospace_workspace.sh #!/usr/bin/env bash
# Workspace names
get_workspace_name() {
case "$1" in
"1") echo "Web" ;;
"2") echo "Misc" ;;
"3") echo "Code" ;;
"4") echo "Media" ;;
*) echo "$1" ;; # Default to SID
esac
}
# Workspace icons
get_workspace_icon() {
case "$1" in
"1") echo " " ;;
"2") echo " " ;;
"3") echo " " ;;
"4") echo "" ;;
*) echo " " ;; # Default icon
esac
}
sketchybar --add event aerospace_workspace_change
# Styling
spaces=(
label.padding_left=0
label.padding_right=6
)
# Retrieve the current focused workspace
FOCUSED_WORKSPACE=$(aerospace list-workspaces --focused)
for SID in $(aerospace list-workspaces --all); do
# Get the name and icon for the workspace
WORKSPACE_NAME=$(get_workspace_name "$SID")
WORKSPACE_ICON=$(get_workspace_icon "$SID")
sketchybar --add item space."$SID" left \
--subscribe space."$SID" aerospace_workspace_change \
--set space."$SID" "${spaces[@]}" \
label="$WORKSPACE_NAME" \
icon="$WORKSPACE_ICON" \
click_script="aerospace workspace $SID; sketchybar --trigger aerospace_workspace_change" \
script="FOCUSED_WORKSPACE=$FOCUSED_WORKSPACE $CONFIG_DIR/plugins/aerospace_workspace.sh $SID"
done plugins/aerospace_workspace.sh #!/usr/bin/env bash
# Define colors
ACT_ICON_COLOR="$(getcolor orange)"
ACT_NAME_COLOR="$(getcolor white)"
INA_ICON_COLOR="$(getcolor fg 50)"
INA_NAME_COLOR="$(getcolor grey)"
# Get the currently focused workspace dynamically
CURRENT_FOCUSED_WORKSPACE=$(aerospace list-workspaces --focused)
# Determine state and update settings
if [ "$1" = "$CURRENT_FOCUSED_WORKSPACE" ]; then
sketchybar --set "$NAME" \
background.drawing=on \
icon.color="$ACT_ICON_COLOR" \
label.color="$ACT_NAME_COLOR"
else
sketchybar --set "$NAME" \
background.drawing=off \
icon.color="$INA_ICON_COLOR" \
label.color="$INA_NAME_COLOR"
fi For the modes.. items/aerospace_mode.sh #!/usr/bin/env zsh
# Aerospace mode settings
sketchybar --add item aerospace_mode center \
--set aerospace_mode \
label.drawing=on \
icon.drawing=on \
icon.padding_left=8 \
icon.padding_right=6 \
label.padding_left=6 \
label.padding_right=8 \
icon.color="$(getcolor red)" \
label.color="$(getcolor grey 50)" \
script="$CONFIG_DIR/plugins/aerospace_mode.sh"
# Add and subscribe to the aerospace_mode_change event
sketchybar --add event aerospace_mode_change \
--subscribe aerospace_mode aerospace_mode_change plugins/aerospace_mode.sh #!/usr/bin/env zsh
# Mode icon
get_mode_icon() {
case "$1" in
main) echo " " ;;
manage) echo "" ;;
*) echo " " ;; # Fallback icon for unknown modes
esac
}
# Mode label
get_mode_label() {
case "$1" in
main) echo "Main Mode" ;;
manage) echo "Manage Mode" ;;
*) echo "Unknown mode" ;; # Fallback label for unknown modes
esac
}
# Get current mode; default to main
MODE="${MODE:-main}"
# Debugging: Log the mode for troubleshooting
#echo "$(date) - Mode: $MODE" >>/tmp/aerospace_mode_debug.log
# Set icon and label
ICON=$(get_mode_icon "$MODE")
LABEL=$(get_mode_label "$MODE")
# Update sketchybar item
sketchybar --set aerospace_mode \
icon="$ICON" \
label="$LABEL" Than you can simply call the modes inside: aerospace.toml: 'exec-and-forget sketchybar --trigger aerospace_mode_change MODE=main' Also don't forget to remove my custom functions/helpers such as Hope this helps! 😁 |
Beta Was this translation helpful? Give feedback.
Take a look here: https://nikitabobko.github.io/AeroSpace/goodness#show-aerospace-workspaces-in-sketchybar
I haven't updated my dotfiles yet but this is what I have so far:
make sure to edit your aerospace config file with:
items/aerospace_workspace.sh