Skip to content

Instantly share code, notes, and snippets.

@fungiboletus
Last active May 3, 2023 14:37
Show Gist options
  • Save fungiboletus/37b4440f4554a4f8042b5330cda5bd0f to your computer and use it in GitHub Desktop.
Save fungiboletus/37b4440f4554a4f8042b5330cda5bd0f to your computer and use it in GitHub Desktop.
Tim time tracker: Hammerspoon Lua script, to remind you to enable time tracking when you work
function isTimTimeTrackingLive()
local preferencesPath = os.getenv('HOME').."/Library/Containers/neat.software.Tim/Data/Library/Preferences/neat.software.Tim.plist"
local preferences = hs.plist.read(preferencesPath)
local data = hs.json.decode(preferences['Tim_Data'])
local tasks = data['tasks']
-- When Tim has a live session, a record has the same start and end timestamp
for key, task in pairs(tasks) do
records = task['records']
for i, record in ipairs(records) do
if record['start'] == record['end'] then
return true
end
end
end
return false
end
-- Run every 60s
hs.timer.doEvery(60, function()
local isConnectedToWorkWifi = hs.wifi.currentNetwork() == 'work-office-ssid'
local hoursSinceMidnight = tonumber(os.date("%H"))
local nowIsWorkingHours = hoursSinceMidnight > 7 and hoursSinceMidnight < 16
local weekday = tonumber(os.date("%w"))
local isWeekend = weekday > 5
local isWorking = isConnectedToWorkWifi or (nowIsWorkingHours and not isWeekend)
if isWorking and not isTimTimeTrackingLive() then
-- Show friendly reminder for 10 seconds
hs.alert.show("Remember to track your time", 10)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment