Author Avatar Image
Alexander Reelsen

Backend developer, productivity fan, likes the JVM, full text search, distributed databases & systems

Using Hammerspoon to enable DnD when screen sharing via Zoom
Oct 30, 2020
2 minutes read

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

# 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

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$", "")


Restart Hammerspoon, fire up a Zoom session, enable screen sharing and you should never see any notification again, while you share your screen!


Back to posts