Note to Self:
When writing an applescript program that needs to run in the background and do something, do not use a loop with a delay inside it. (It hogs the CPU).
Instead, use an “on idle”, and save with “Stay Open” checked.
on idle commands... set secondsInterval to 5 return secondsInterval end idle