-- -------------------------- -- Alert When App Not Focused -- -------------------------- local alertInSeconds = 60 * 20 local alertAppName = 'App You Want to Focus Here' local alertTimer local function stopTimerAlertTimer() if alertTimer then alertTimer.stop() alertTimer = nil end end local function notificationClicked() hs.application.launchOrFocus(alertAppName) end local function sendNotification() local notification = hs.notify.new(notificationClicked, { title = 'Time to focus ' .. alertAppName, informativeText = 'Click to return', soundName = 'Glass.aiff' }) notification:send() end local function appFocused(appName, eventType) if appName ~= alertAppName then return end if eventType == hs.application.watcher.activated then stopTimerAlertTimer() hs.alert.show('Welcome back to ' .. alertAppName) elseif eventType == hs.application.watcher.deactivated then stopTimerAlertTimer() alertTimer = hs.timer.delayed.new(alertInSeconds, sendNotification) alertTimer:start() hs.alert.show(alertInSeconds / 60 .. ' minute return timer started for ' .. alertAppName) end end if alertAppName then local watcher = hs.application.watcher.new(appFocused) watcher:start() end