A Hammerspoon script that lets you click macOS notifications using a keyboard shortcut (Cmd+Alt+N) without using your hands.

hs.hotkey.bind({"cmd", "alt"}, "N", function()
local screen = hs.screen.primaryScreen():frame()
local testX = screen.x + screen.w - 180
local testY = screen.y + 70
local el = hs.axuielement.systemElementAtPosition(testX, testY)
if not el then
hs.alert.show("Notification not found")
return
end
local banner = el:attributeValue("AXParent")
if not banner or banner:attributeValue("AXRole") ~= "AXGroup" then
hs.alert.show("Banner element not found")
return
end
local pos = banner:attributeValue("AXPosition")
local size = banner:attributeValue("AXSize")
if not pos or not size then
hs.alert.show("Failed to get coordinates")
return
end
local clickPoint = { x = pos.x + size.w / 2, y = pos.y + size.h / 2 }
hs.eventtap.leftClick(clickPoint)
end)
添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论