Latest post

Daily shutdown script for Timingapp

When I'm in the middle of work I often tend to overlook how long I've already worked on any given day, especially when working from home during Covid where I mostly don't have fixed start or end dates, like so many of us.

To avoid having my overtime balance increase unintentionally by working half an hour here and there I've created a script for myself based on the excellent Timing to see when I've worked about 7.5h to allow me to begin to shut down my work for the day.

You can do that with a small Applescript by looking for the total time tracked today in seconds and then creating a notification. There's probably a more efficient way than running this command every minute and just comparing number of seconds, but it seems to do the trick.

In addition to the notification I also force dark mode to nudge myself a bit more proactively.

tell application "TimingHelper"
    if not scripting support available then
        error "Scripting support requires a Timing Expert license. Please contact support via to upgrade."
    end if
end tell

tell application "TimingHelper"
    set usageData to get time summary between current date and current date
    set total to overall total of usageData
     # work day 8 * 60 * 60:    28'800s
     # threshold 7.5 * 60 * 60: 27'000s
    if total ≥ 27000 and total < 27060 then
        display notification "You have worked 7.5h, begin shutting down." with title "Timing alert" sound name "Frog"
        tell application "System Events"
            tell appearance preferences
                set dark mode to true
            end tell
        end tell
    end if
    delete usageData
end tell

Now add an agent to ~/Library/LaunchAgent such as the one shown below like com.example.timing_monitor.plist and enable it with launchctl load com.example.timing_monitor.plist and you should be good to go.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
    <string>/your/path/your script.scpt</string>

Tags: applescript