But I have some troubles getting to run this script from within hammerspoon. At the moment I have
-- Close notifications
hs.hotkey.bind(hyper, "n", function()
hs.alert.show("Close notifications")
script = [[
my closeNotif()
on closeNotif()
tell application "System Events"
tell process "Notification Center"
set theWindows to every window
repeat with i from 1 to number of items in theWindows
set this_item to item i of theWindows
try
click button 1 of this_item
on error
my closeNotif()
end try
end repeat
end tell
end tell
end closeNotif ]]
ok,result = hs.applescript(script)
hs.alert.show(result)
end)
I see the "Close" button flash up blue as if it would be clicked, but it doesn't close. When I run this script from Script Editor it works like expected.