1. Home
  2. Mac OS X
  3. Show a notification on macos with a script

How to show a notification on macOS with a script

You can use scripts and automator actions/workflows to do all sorts of things. Scripting is a great way to get most things done and if you need to show a notification on your desktop, that’s the way to go. We’ve covered how you can show toast notifications on Windows 10. If you want to show a notification on macOS, a script will do the job.

Show a notification on macOS

Open ScriptEditor. You can search for it in Spotlight or you can search for it in the Applications folder, or you can try Launchpad.

Create a new document in ScriptEditor and enter the following.

display notification "Notification message" with title "Title of notification"

Save it as an application and you will be able to run it. When run, it will show a notification like other apps on macOS.

This notification will of course have the standard script icon which isn’t that appealing. If nothing else, it doesn’t let you visually tell what notification you’re seeing.

You can change the icon for a script but not from the ScriptEditor app. Make sure the script is saved as an application. Navigate to the folder you’ve saved this script-application to. Right-click it and select Show package contents from the context menu.

In the folder that opens, go to Contents>Resources. In this location, you will see a file called applet.icns. This is the icon file that you need to replace. Go ahead and find an icon to use for your notification. Move it to this folder and rename it to “applet.icns”. It goes without saying that the original file will have to be replaced. Close the folder and run the application.

The notification will show up with the new icon that you set. It won’t change the icon that’s used for other scripts.

The script above is basic. The notification will have a title and a message however, you can also add a subtitle by adding the following at the end.

subtitle "subtitle"

Notifications on macOS also play an audio alert. By default, it will use the default notification sound however, you can specify which notification to use by adding the following at the end. Replace ‘Sound Name’ with the name of a sound.

sound name "Sound Name"

The sound name/file must be one that is already present in one of the following locations;

~/Library/Sounds

or

/System/Library/Sounds

Those are all the changes you can make to the notification that is shown.