A small PowerShell experiment that tracks which Windows application is in the foreground and accumulates how many seconds each process has been active. It was built to learn PowerShell and Win32 interop, as a starting point for personal screen-time tracking.
- PowerShell (Windows)
- Win32
user32.dllGetForegroundWindowviaAdd-Type(inline C#)
From a PowerShell session on Windows:
cd scripts/collection
./Collect.ps1The script loops forever. Each iteration it picks a random 5 to 35 second wait, looks up the process that owns the foreground window, and adds the wait time to that process's running total. Every few iterations it writes the totals to output/userData.txt. Stop it with Ctrl+C.
The relative output path means the script must be started from scripts/collection.
scripts/collection/- the foreground-window sampler (Collect.ps1) and its helpersscripts/storage/- a stub save scriptscripts/report/- empty placeholders for a future reportoutput/- sample output from a local run
Work in progress. Only the collection loop works. The storage and report scripts are empty or placeholder stubs, and the sampling is coarse (random intervals, not exact timing).