-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnd.lua
30 lines (24 loc) 路 764 Bytes
/
dnd.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--
-- Enable / disable Do Not Disturb and Bluetooth based on conditions
--
local dndApps = {'IINA'}
local logger = hs.logger.new('dnd', 'debug')
Dn = {}
function Dn.isWorkingHours()
local hour = tonumber(os.date('%H'))
local day = tonumber(os.date('%w'))
return (hour >= 9) and (hour < 18) and (day ~= 0) and (day ~= 6)
end
local function appWatcherHandler(appName, eventType)
if (not tl.isInList(dndApps, appName)) or Dn.isWorkingHours() then
return
end
if (eventType == hs.application.watcher.launched) and
(tl.isInList(dndApps, appName)) then
dnd.turnOn()
elseif (eventType == hs.application.watcher.terminated) then
dnd.turnOff()
end
end
DndAppWatcher = hs.application.watcher.new(appWatcherHandler)
DndAppWatcher:start()