Documentation Archive

Developer

Mac Automation Scripting Guide

Displaying Notifications

Notification Center offers another opportunity for providing feedback during script execution. Use the Standard Additions scripting addition’s display notification command to show notifications, such as status updates as files are processed. Notifications are shown as alerts or banners, depending on the user’s settings in System Preferences > Notifications. See Figure 24-1 and Figure 24-2.

Figure 24-1A banner notification image: ../Art/notification-banner_2x.png
Figure 24-2An alert notification image: ../Art/notification-alert_2x.png

To show a notification, provide the display notification command with a string to display. Optionally, provide values for the with title, subtitle, and sound name parameters to provide additional information and an audible alert when the notification appears, as shown in Listing 24-1 and Listing 24-2.

APPLESCRIPT

Open in Script Editor

Listing 24-1AppleScript: Displaying a notification
  1. display notification "All graphics have been converted." with title "My Graphic Processing Script" subtitle "Processing is complete." sound name "Frog"

JAVASCRIPT

Open in Script Editor

Listing 24-2JavaScript: Displaying a notification
  1. var app = Application.currentApplication()
  2. app.includeStandardAdditions = true
  3. app.displayNotification("All graphics have been converted.", {
  4. withTitle: "My Graphic Processing Script",
  5. subtitle: "Processing is complete.",
  6. soundName: "Frog"
  7. })