Skip to content

Send cross-platform desktop notifications from Julia

License

Notifications You must be signed in to change notification settings

haberdashPI/Alert.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alert

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Build Status

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:

  1. Call alert() after a long-running piece of code.
  2. Put long-running code inside the @alert macro.
  3. 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:

The alert() function

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

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()
end

The REPL hook

In 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
end

Changing backends

You can implement any backend you want for alert. See the docstring for Alert.set_alert_backend! for more details.

Built-in backends

  • apple_alert! allows you to modify some UX details of the alert notification on MacOS. See its docstring.

Troubleshooting

  • Notification fails to display on Windows: check to make sure you have Notifications turned on in "Notifications & actions" in your OS settings. Window of the Windows 10 "Notifications & actions"

Extensions

If you want to use alert remotely or in an online IDE, where you can't get local UX notifications, you can use AlertPushover.