A few years ago Apple added Auto-Save and Versions (in Lion), which resulted in doing away with the traditional Save, Don’t Save, Cancel prompt that would appear when closing a document with unsaved changes. If you dislike Auto-Save, it’s still possible to disable Auto-Save and get prompted when closing a document. While this disables Auto-Save, the old Don’t Save button now says Revert Changes.

The traditional macOS save prompt with Don’t Save
The traditional macOS save prompt with Don't Save

The modern macOS save prompt with Revert Changes
The modern macOS save prompt with Revert Changes

The name change alone isn’t a problem, but with this change the command-D shortcut to select Don’t Save no longer exists. Even worse, there’s no replacement. This change was almost five years ago, so I’m not holding out much hope for a new shortcut to arrive.

After far too many times of closing a document with changes and having to reach for the mouse to click Revert Changes, I finally started looking for a solution. I recently started using Hammerspoon to perform some basic automation tasks with keyboard shortcuts. Hammerspoon has extensive support for window manipulation through the system’s accessibility API, so I thought it might be capable of simulating a click on the Revert Changes button. I was initially disappointed to find that Hammerspoon’s accessibility API is limited to just windows, but I found an experimental module that gives full access to the system’s accessibility API.

After installing the axuielement module in ~/.hammerspoon I was put together a hot key that could click on Revert Changes, no mouse needed:

hs.hotkey.bind({"alt", "ctrl"}, "R", function()
    local axui = require("hs._asm.axuielement")
    local revertButton = axui.windowElement(hs.window.focusedWindow()):elementSearch({role="AXButton", title="Revert Changes"})[1]

    revertButton:performAction("AXPress")
end)

If you’re not familiar with Hammerspoon or Lua, this is a script that goes in ~/.hammerspoon/init.lua. It registers a hot key that searches the current window for a button named Revert Changes, then clicks on it.

Now when a save prompt appears I can press control-option-R to dismiss it, no mouse needed. One small issue with this approach is it is a global hot key, which means it is always active so you have to choose a hot key that isn’t used for anything else. It would be even better to use a hot key such as command-R, but it would conflict with regular command-R shortcuts (such as Reload Page in Safari).

Maybe someday we’ll get a replacement system shortcut (31936893 for anyone who wants to file a bug with Apple), but until then at least I have an alternative.