TAP TO HIDE SIDEBAR

Notification Auto-Approval Applet

In macOS, for the sake of security and by design, there are no mechanisms to have Notification Center alerts automatically approved or dismissed.

However, as this folder action example of an autonomous AirDrop image repository demonstrates, there may be times when you intentionally want the computer automatically approve incoming AirDrop downloads.

The AppleScript applet provided on this page can perform the task of automatically approving downloads from AirDrop notification alerts.

IMPORTANT: This applet is designed to work with macOS Mojave (v10.14) or higher. It will not work with earlier versions of macOS.

DOWNLOAD the completed notification approval applet. (macOS Mojave required)

use framework "Foundation" use scripting additions property alertTitles : {"AirDrop"} property closeButtonTitles : {"OK", "Decline", "Close"} property approveButtonTitles : {"Accept"} property actionMenuItem : "Save to Downloads" global monitorSound, denySound, approveSound, alertSound on run set monitorSound to current application's NSSound's soundNamed:"Bottle" set alertSound to current application's NSSound's soundNamed:"Morse" set denySound to current application's NSSound's soundNamed:"Frog" set approveSound to current application's NSSound's soundNamed:"Glass" end run on idle try tell application "System Events" tell process "NotificationCenter" monitorSound's play() repeat with i from 1 to the count of windows set aWindow to item i of windows if subrole of aWindow is "AXNotificationCenterAlert" then set alertTitle to value of static text of aWindow -- alertSound's play() if alertTitle is in alertTitles then set alertOptions to every menu button of aWindow if (count of alertOptions) is not 0 then repeat with q from 1 to the count of alertOptions set aButton to item q of alertOptions set aButtonTitle to title of aButton if aButtonTitle is in approveButtonTitles then click aButton tell menu 1 of aButton click menu item actionMenuItem end tell approveSound's play() exit repeat end if end repeat end if end if end if end repeat end tell end tell on error errorMessage activate display dialog errorMessage buttons {"OK"} default button 1 tell me to quit end try return 3 end idle

 01-02  AppleScriptObjective-C “use statements” function as import declarations for accessing the macOS Cocoa Foundation frameworks and the default AppleScript scripting additions. In this applet, the NSSound classes from Foundation are used to play system sounds.

 04-07  Properties whose values are the strings used by the targeted notification dialogs. You can edit these values for other languages.

 09  Global variable declarations indicate the variables available throughout the entire script. Note that properties are global in nature and do not need to identified as global.

 11-16  The script’s main run handler, executed when the applet starts up, instantiates values for the global variables, which in this case are system alert sound objects accessed using the NSSound Foundation class soundNamed:nameString method.

 18-55  An idle handler that is executed periodically by the applet that was saved as an application with the “Stay open after run handler” option selected.

 20-40  This script addresses the built-in System Events application to query and control the notification windows of the macOS NotificationCenter application. It checks the notification title to see if it indicates an AirDrop action, and if it does, checks the notification alert to see if it displays and options popup menu. If there is an alert options menu, then the script will select the option to save the AirDrop item to the downloads folder. If the notification alert does not offer the option to download, it is ignored by the idle handler.

 54  A value in seconds indicating the amount of time between executions of the idle handler. By default, the idle time is set to 3-seconds. Adjust as you wish.

Saving the Applet

To create the Notification Approval applet, paste the provided script code into a new script window in the macOS Script Editor application (or the excellent Script Debugger editor app). Make whatever edits you wish, and then choose type Command-S (⌘S) or choose “Save…” from the File menu.

applet-save-dialog

 1  The Save sheet displayed over the script document window.

 2  Save the script as an applet by selecting “Application” from “File Format” popup menu.

 3  Since this example script contains an idle handler, select the option “Stay open after the run handler” which will enable the applet to remain open and active instead of running and stopping as with a standard applet or script.

 4  The save destination can be wherever you like. We suggest creating an “Applications” folder in your Home directory as a secondary application repository to the top-level “Applications” folder.

 5  Enter a name for the applet.

 6  Click the Save button to save the script as an application in the specified directory.

Automation Security

Beginning with macOS Mojave (v10.14) script applications (applets/droplets) require explicit user approval to send Apple Events to other applications. This approval only is required once during the first running of the applet.

applet-security-dialog-events

Once approved, the applet will be added to the Automation access list in the Privacy & Security system preference pane (see Automation Security for more information):

automation-access-list

Also, since the applet script uses the Accessibility frameworks to query and control the UI of the NotificationCenter application, it will require a second one-time security approval for that as well:

accessibility-access-dialog

The “Accessibility Access List” controls are available in the Accessibility category of the Privacy tab of the Security & Privacy system preference pane (see Assistive Access for more information):

accessibility-access-list

Stopping the Applet

When you are ready to stop the applet, simply make it the frontmost application and type Command-Q (⌘Q) or choose Quit from the applet’s File menu.

UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER