Detecting launched apps to update focused Aerospace Workspace #666
Unanswered
RNBermudez
asked this question in
Q&A
Replies: 1 comment
-
I almost managed to make it work. However, there were a few issues that I couldn’t resolve:
Other than that, it does what is supposed to do: hide empty workspaces and show icons for the currently running applications on each workspace. Thanks all. Here’s the updated code for anyone who might be interested: Aerospace item # Aerospace Item configuration for SketchyBar
# It is intended to be sourced by other SketchyBar configuration scripts, not executed directly.
source "${CONFIG_DIR}/icons.sh"
sketchybar --add event aerospace_workspace_change
workspaces=""
if [[ -z "${workspaces}" ]]; then
workspaces=$(aerospace list-workspaces --all)
fi
for sid in ${workspaces}; do
apps=$(aerospace list-windows --workspace "${sid}" | awk -F '\\| *' '{print $2}')
icons=""
for app in ${apps}; do
icons+="$(workspace_icons "${app}")"
space_label="${apps[@]}"
done
space=(
"background.drawing=off"
"icon=${sid}"
"label=${icons}"
"click_script=aerospace workspace ${sid}"
"script=${CONFIG_DIR}/plugins/aerospace.sh ${sid}"
)
if [[ -z "${apps}" ]]; then
space+=("icon.drawing=off" "label.drawing=off")
fi
sketchybar --add item space."${sid}" left \
--subscribe space."${sid}" front_app_switched aerospace_workspace_change \
--set space."${sid}" "${space[@]}"
done Aerospace plugin #!/usr/bin/env bash
source "${CONFIG_DIR}/colors.sh"
source "${CONFIG_DIR}/icons.sh"
function get_workspace_running_apps() {
local workspace=${1}
local apps=$(aerospace list-windows --workspace ${workspace} | awk -F '\\| *' '{print $2}')
local running_apps=""
for app in ${apps}; do
running_apps+="$(workspace_icons "${app}")"
done
printf "%s" "${running_apps}"
}
function update_on_workspace_change() {
local workspace=${1}
local apps=$(get_workspace_running_apps "${workspace}")
local space=(
label="${apps}"
)
if [[ "${workspace}" = "${FOCUSED_WORKSPACE}" ]]; then
space+=(
"label.color=${aerospace_active_fg_color}"
"icon.drawing=on"
"label.drawing=on")
else
space+=("label.color=${aerospace_inactive_fg_color}")
if [[ -n "${apps}" ]]; then
space+=("icon.drawing=on" "label.drawing=on")
else
space+=("icon.drawing=off" "label.drawing=off")
fi
fi
sketchybar --set ${NAME} "${space[@]}"
}
update_on_front_app_switched() {
local workspace=${1}
local apps=$(get_workspace_running_apps "${workspace}")
local space=(
label="${apps}"
)
sketchybar --set "${NAME}" "${space[@]}"
}
case "${SENDER}" in
"aerospace_workspace_change")
update_on_workspace_change "${1}"
;;
"front_app_switched")
update_on_front_app_switched "${1}"
;;
"forced")
exit
;;
*)
update
;;
esac |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello. I am having trouble updating the focused Aerospace Workspace item when a new application is launched on that workspace.
I have the following scripts for my Aerospace item and script, which in short displays the icons of running applications inside each workspace item and hide workspaces without running applications.
Aerospace Item
Aerospace script
Launching a new application, switching workspace back and forth will render the new application icon as expected, but I would like it to render without me switching workspaces. Is this something possible? Where should I be looking at?
I tried using the event
front_app_switched
but couldn't make it work.On an unrelated note, there is a very noticeable lag on the items update whenever I switch workspace. I reckon that calling
aerospace list
isn't free, but it feels way too slow. Maybe there is something off on my config?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions