Alert provides a cross-platform means of displaying a notification to the user in Julia. It should work on MacOS, Windows 10 (even under WSL2) and many flavors of Linux. This is handy for long-running scripts. You can also use an extension (AlertPushover) to send notifications to your phone or a webapp when working remotely.
There are three ways to use alert:
- Call
alert()after a long-running piece of code. - Put long-running code inside the
@alertmacro. - Call
alert_REPL!and any long-running code sent to the REPL will display a notification.
Before using alert() at the end of a long-running script, it would be good to
test that it actually works on your system: some linux distros may not have an
appropriate program installed to display the notification. Loading Alert
should warn you if it can't find an appropriate executable to send the
notification. Just read the error message that is displayed to see what program
you need to install.
Table of Contents:
To use alert() just add it to some long-running code.
using Alert
for i in 1:10_000
long_running_function()
end
alert("Your julia script is finished!")The @alert macro displays a message if the code passed to it runs for longer
than 2 seconds (or a custom value). This is especially handy when using
ProgressMeter, like so.
@alert @showprogress for i in 1:10_000
long_running_function()
endIn Julia 1.5 or greater, if you want any long-running command at the REPL to
send a notification, you can use alert_REPL!. It takes the same arguments as
@alert and will wrap any code passed to the Julia REPL in a call to @alert.
You can add the following to your startup.jl file to have it work in every
Julia session.
try
using Alert
alert_REPL!()
catch e
@warn e.msg
endYou can implement any backend you want for alert. See the docstring for Alert.set_alert_backend! for more details.
apple_alert!allows you to modify some UX details of the alert notification on MacOS. See its docstring.
- Notification fails to display on Windows: check to make sure you have Notifications turned on in "Notifications & actions" in your OS settings.
If you want to use alert remotely or in an online IDE, where you can't get local UX
notifications, you can use AlertPushover.
