Keyboard control of Big Sur notification alerts
source link: https://akrabat.com/keyboard-control-of-big-sur-notification-alerts/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
With the release of Big Sur, my scripts for keyboard control of macOS notification alerts stopped working.
With a bit of experimentation and help from Google, I have written new ones.
Closing an alert
To close a notification alert on Big Sur, conceptually we want to press the X button that appears when you hover over it. The AppleScript to do this is:
This is much more complicated than just clicking button 1 of window 1 which is what we did before! In Big Sur, NotificationCenter now has a set of actions within the window and we iterate over them looking for the one called “Close” and then execute it.
This closes the notification alert.
Running from the command line
To run it from the command line, I have a file called close-alert stored in /usr/local/bin that runs osascript
for me:
/usr/local/bin/close-alert:
This is marked as executable (chmod a+x /usr/local/bin/close-alert) so that I can close a notification alert from Terminal
Running from Alfred
I have also added to Alfred as a workflow. This requires two steps: a keyword step called “close alert” which takes no argument that is linked to a run script step which runs /usr/local/bin/close-alert.
This allows me to type “close alert” into Alfred to close the notification.
This gives me back keyboard control of closing the Big Sur notifcation alerts which is the operation I do most.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK