7 hours ago · Tech · hide · 0 comments

For over two weeks, I found that the front application would, every hour or so, lose focus to… something. No obvious culprit made itself known, so I asked an agent to write me a script to figure it out and it came up with: #!/bin/zsh # Logs every change of the frontmost (focused) app with a timestamp. PREV="" while true; do FRONT=$(lsappinfo info -only name $(lsappinfo front) 2>/dev/null | sed 's/.*"\(.*\)".*/\1/') if [[ "$FRONT" != "$PREV" && -n "$front" ]]; then printf '%s -> %s\n' "$(date '+%H:%M:%S.%2N')" "$FRONT" | tee -a ./focus-watch.log PREV="$FRONT" fi sleep 0.15 doneTranslated into plain-english, this runs a check every 0.15 seconds, seeing if the front most application (the focused one) has changed and if so, record the newly focused app to focus-watch.log whilst printing to screen. The learning for me, lsappinfo. Running man lsappinfo reports that lsappinfo can “Control and query CoreApplicationServices about the app state on the system” and that front lists as number one…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.