قالب وردپرس درنا توس
Home / Mac / How to display a macOS alert with a script

How to display a macOS alert with a script



You can use scripts and automation actions / workflows to do all kinds of things. Scripting is a great way to get the most out of it, and if you need to show an alert on your desktop, this is the way to go. We've covered how to display toast notifications in Windows 10. To display a notification on macOS, a script will do the job.

View Notification on macOS

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

Create a new document in ScriptEditor and type the following.

  show alert "Alert message" with title "Alert title" 

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

Of course, this notification will have the default script icon which is not appealing. If nothing else, it will not let you visually tell what alert you are seeing.

You can change the icon for a script, but not from the ScriptEditor app. Make sure the script is saved as a program. Navigate to the folder where you saved this script application. Right-click it and select View Package Content from the context menu.

Go to Content> Resources in the folder that opens. On this site you will see a file called applet.icns. This is the icon file you need to replace. Go ahead and find an icon that you want to use for the notification. Move it to this folder and rename it to “applet.icns”. It goes without saying that the original file must be replaced. Close the folder and run the application.

The notification will appear with the new icon you specified. It will not change the icon 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 a sound alert. By default, it uses the default notification sound, but you can specify which notification you want to use by adding the following at the end. Replace & # 39; Sound Name & # 39; with the name of a sound.

  sound name "Sound Name" 

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

  ~ / Library / Sounds 

or

  / System / Library / Sounds 

These are all the changes you can make to the notification that appears.


Source link