Closed chrisgrieser closed 6 months ago
The way I would keep track of the previously focussed app in sketchybar would not be different from a scripting approach: when the front app changes, write the current front app to some cache and use it on the next event to retrieve the previously focused window.
For example use this handle script for the front_app_switched
event:
#!/bin/bash
if [ "$SENDER" = "front_app_switched" ]; then
PREVIOUS_FRONT_APP=$(</tmp/front_app)
echo "$INFO" > /tmp/front_app
sketchybar --set $NAME label="$INFO" icon.background.image="app.$INFO"
fi
Ah, yeah, that works as well. For reference if anyone finds this issue:
# only trigger on deactivation of $TASK_APP
if [[ "$SENDER" = "front_app_switched" ]]; then
data="/tmp/sketchybar_front_app"
[[ -f "$data" ]] && deactivated_app=$(<"$data")
echo -n "$INFO" >"$data"
[[ "$deactivated_app" != "$TASK_APP" ]] && return 0
fi
do …
Right now, the event
front_app_switched
does populateINFO
with the name of the app that has been activated (become frontmost).For various scripting purposes, it is useful to get the name of the app that was deactivated, for instance things like "update the counter of this app when closing/deactivating it"