The AppleScript “display notification” Command

The display notification command can be used anywhere within a script to trigger a system notification. Here is the scripting dictionary listing for the command:

display notification v : Display a notification. At least one of the body text and the title must be specified.
display notification [text] : the body text of the notification
[ with title (text) ] : the title of the notification (default is the name of the calling application).
[ subtitle (text) ] : the subtitle of the notification
[ sound name (text) ] : the name of the sound to play

In the following script example  (⬇ see below ) , the display notification command is placed after the processing statements in the droplet code, and will trigger the display a notification message indicating the number of items processed.

on open theseItems
 set the defaultRBGColor to {0, 0, 65535}
 set the frameThickness to 48
 try
 repeat with thisItem in theseItems
 tell application "Image Events"
 launch
 set thisImage to open file (thisItem as string)
 copy dimensions of thisImage to {W, H}
 pad thisImage to ¬
 dimensions {W + frameThickness, H + frameThickness} ¬
 with pad color defaultRBGColor
 save thisImage with icon
 close thisImage
 end tell
 end repeat
 display notification ((count of theseItems) as string) & ¬
 " images were processed."
 delay 1 --> allow time for the notification to trigger
 on error errorMessage number errorNumber
 display alert errorNumber message errorMessage
 end try
end open

IMPORTANT: if the display notification command is the last action in the script, place a statement containing a delay after the command, in order to give the notification enough time to be triggered before the script stops. In this example  (⬆ see above )  a delay of one second is ample time.

applescriptexample

 (⬆ see above )  A notification banner triggered by the example AppleScript script droplet.

TOP | CONTINUE