TLDR; Do you keep forgetting to set DnD mode when doing a zoom screenshare and then all your secret cabal appointments keep popping up? Here is a quick way of solving this with Hammerspoon.
First, I assume you already have installed Hammerspoon. Hammerspoon supports extensions called Spoons. One of those is a relatively new spoon, that can react to events emitted by the Zoom client, conveniently named Zoom.Spoon.
Two of those events mark the start and end of sharing a screen, as well as starting/ending the zoom application.
Installing the do-not-disturb CLI tool
There is a small CLI tool written in swift as part of a npm package, which
allows setting the DnD state via the command line. In order to not use node
to trigger this, but just run the command line tool, you can download the
package and extract the binary. This also ensures that upgrading your
global node version does not change the existence of this script as it would
be if you run npm -g install
and do a global install. Thus a little more
effort now will ensure everything is stable in the long run.
cd /tmp
wget https://registry.yarnpkg.com/@sindresorhus/do-not-disturb/-/do-not-disturb-1.1.0.tgz
# extract only the do-not-disturb binary
tar zxf do-not-disturb-1.1.0.tgz --include package/do-not-disturb \
-O > ~/bin/do-not-disturb
chmod 755 ~/bin/do-not-disturb
If you are interested in the source, check the do-not-disturb repository on GitHub.
You can now run the following commands
~/bin/do-not-disturb on
~/bin/do-not-disturb off
~/bin/do-not-disturb status
~/bin/do-not-disturb toggle
Time to configure the spoon.
Setting up Zoom.spoon
Install Zoom.spoon like this
cd ~/.hammerspoon/Spoons
git clone https://github.com/jpf/Zoom.spoon
Add the following to your hammerspoon configuration, like
~/.hammerspoon/init.lua
.
-- enable DND, when sharing is done via zoom
-- this requires the npm package do-not-disturb to be installed
local dndStatusBeforeZoom
updateZoomStatus = function(event)
-- comment this out after debugging...
hs.printf("updateZoomStatus(%s)", event)
-- only disable do not disturb if it was disabled zoom was started
if (event == "from-sharing-to-meeting") and (dndStatusBeforeZoom == "off") then
hs.execute("~/bin/do-not-disturb off")
-- always set dnd on screen share
elseif (event == "from-meeting-to-sharing") then
hs.execute("~/bin/do-not-disturb on")
-- restore startup status on quit
elseif (event == "from-running-to-closed") then
hs.execute("~/bin/do-not-disturb " .. dndStatusBeforeZoom)
-- read current status
elseif (event == "from-closed-to-running") then
dndStatusBeforeZoom = hs.execute("~/bin/do-not-disturb status"):gsub("\n$", "")
end
end
hs.loadSpoon("Zoom")
spoon.Zoom:setStatusCallback(updateZoomStatus)
spoon.Zoom:start()
Restart Hammerspoon, fire up a Zoom session, enable screen sharing and you should never see any notification again, while you share your screen!
Resources
- Hammerspoon homepage
- Zoom Spoon
- do-not-disturb npm package
- Creating A Productive osx Environment - Hammerspoon