Created
April 9, 2018 16:51
-
-
Save mutewinter/62a01d75fac3b3d8539297a32aefbac3 to your computer and use it in GitHub Desktop.
Hammerspoon App Focus Alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- -------------------------- | |
-- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment