Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.8: AppleScript to close iCal Alerts System 10.8
I'd just installed OS X 10.8, and booted to find the right side of my screen covered in Birthday and Calendar notifications! Since installing I've clicked 'Close' on way too many iCal notification alerts.

Here's a script to close them all for you in one fell swoop. Since I still want iCal to popup a Notification alert for event alarms I've set, I don't want to simply disable all the iCal notifications (or set them to temporary banner alerts).

However, it still occurs that sometimes a small pile of alerts have accrued while I was away from the computer, and I really hate hitting 'Close' a bunch of times.

So, followng is a script to simply close all the piled-up Notification Alerts. The script was put together using these two webpages for inspiration: http://macosxautomation.com/mavericks/notifications/01A.html (most of the nice code comes from here) and http://apple.stackexchange.com/questions/52848/how-do-i-click-a-button-using-applescript (just how to click a button with AppleScript).

on run
 closeNotifications()
end run

on closeNotifications()
 try
  -- This function closes all currently displaying notification alerts. It used to also return the titles of each notification, which I have commented out to disable.
  tell application "System Events"
   tell process "Notification Center"
    set theseWindows to every window whose subrole is "AXNotificationCenterAlert" or subrole is "AXNotificationCenterBanner"
    --set theseTitles to {}
    repeat with thisWindow in theseWindows
     try
      -- Save the title of each alert window:
      --set thisTitle to the value of static text 1 of scroll area 1 of thisWindow
      --set the end of theseTitles to thisTitle
      
      -- Close each alert:
      click button "Close" of thisWindow
     end try
    end repeat --"theseWindows"
    --return theseTitles
   end tell -- "NotCenter"
  end tell -- "SysEvents"
  
 on error errorMessage number errorNumber
  if errorNumber is errorNumber then
   my addAppletToAccessibilityList()
   error number -128
  end if
 end try
end closeNotifications

on addAppletToAccessibilityList()
 -- This function gets the user to enable Accessibility, for scripting the UI interface (hitting buttons etc.)
 set thisAppletFile to (path to me)
 tell application "Finder" to reveal thisAppletFile
 tell application "System Preferences"
  launch
  activate
  
  reveal anchor "Privacy_Assistive" of pane id "com.apple.preference.security"
  
  activate
  
  display alert 
   "Add Applet to Accessibility" message "In order to respond to user clicks on Notification panels and alerts, this applet must be added to the lost of apps approved to use accessibility controls of the OS." & return & return & 
   "To add this app:" & return & return & 
   "1) Click the lock icon (if it is locked) and enter your password." & return & return & 
   "2) If 'SystemUIServer.app' is in the list, check the box next to it's name." & return & return & 
   "Otherwise, if the applet's name is in the list, check the box next to it's name. If it's not in the list, drag the applet (currently shown in the Finder) into the list area." & return & return & 
   "3) Click the lock to re-lock the preference pane, close System Preferences."
 end tell
end addAppletToAccessibilityList


[crarko adds: I haven't tested this one, as I don't run Mountain Lion any more. I remember the problem very well, though. I did compile the script successfully.]
    •    
  • Currently 1.09 / 5
  You rated: 3 / 5 (55 votes cast)
 
[11,073 views]  

10.8: AppleScript to close iCal Alerts | 2 comments | Create New Account
Click here to return to the '10.8: AppleScript to close iCal Alerts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.8: AppleScript to close iCal Alerts
Authored by: stib on Apr 16, '14 07:10:47AM

Can't you just alt-click on one to dismiss them all? Or is that Growl that I'm thinking of?



[ Reply to This | # ]
10.8: AppleScript to close iCal Alerts
Authored by: dfbills on May 28, '14 08:47:14AM

Very nicely done. I especially liked the accessibility note.

---
-d



[ Reply to This | # ]