[wce_code id=”10″]
If there are times when you want to close or open in one fell swoop, all the on screen Alerts and banners that Notification centre has populated your screen with. But could not find a way.
One way you can is by creating an Automator service to run the below Applescripts and give them a keyboard shortcut in the System Preferences Keyboard shortcuts to do so.
Here is how.
In Automator choose to create a new service
Add a Run Applescript Action
Replace it’s standard code with:
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
Set Service receives [no input] in [any application]
Save the service
Open the Keyboard shortcuts in System prefs and set your shortcut for your service under ‘Services’
Now any newly launched app will pick the keyboard shortcut up.
[wce_code id=”3″]
If you want to click the ‘Show’ button on an Alert Notification. you change the button you click from 1 to 2.
click button 2 of this_item
Banner notifications do not have a button 2.
But you can just click the window.
So this code should take care of Showing.
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
set cnt to count buttons of this_item
try
if cnt > 1 then
click button 2 of this_item
else
click this_item
end if
on error
my closeNotif()
end try
end repeat
end tell
end tell
end closeNotif