How can I track active application usage on Wayland via a shell script on ubuntu?

I'm trying to create a script that monitors my active window every minute and logs the time I spend on each application. The goal is to:

Monitor which application/window is active every minute.
Log cumulative time per application (e.g., Browser: 2 hours, VS Code: 3 hours).
Generate daily/weekly usage reports.
Trigger an alert if any non-productive app (e.g., social media, YouTube) is used for more than 1 hour.

I'm running on a Wayland session (e.g., using Sway, GNOME, or Hyprland) where traditional X11 tools like xdotool don’t work. Question: What command-line tools or methods can I use in a shell script to reliably determine the currently active window on Wayland, log usage data, and generate notifications? Any examples or pointers specific to Wayland would be greatly appreciated.

I'm expecting first I should be told about the commands that will be required and then about the script.

Upvotes: -2

Views: 44

Answers (0)

Related Questions