Native Terminal Notifications on Pipeline completion

So when running pipeline tests locally, sometimes a test takes a minute or two, and I’ll check the nf-core Slack or something else while waiting.

I wanted a native notification when the test was completed, and I had previously set up various aliases.

I tossed this function in ~/.nextflow/config on my laptop

def sendTerminalNotification(String protocol, String title, String message) {
    def ESC = "\u001b"
    def BEL = "\u0007"
    def escapeSequence

    switch (protocol.toLowerCase()) {
        case "iterm2":
            escapeSequence = "${ESC}]1337;Notify=title=${title};body=${message}${BEL}"
            break
        case "osc9":
            escapeSequence = "${ESC}]9;${title} ${message}${BEL}"
            break
        case "osc777":
            escapeSequence = "${ESC}]777;notify;${title};${message}${BEL}"
            break
        default:
            println "Unsupported protocol. Using basic print."
            println "${title}: ${message}"
            return
    }

    System.out.print(escapeSequence)
    System.out.flush()
}

And then added a workflow.onComplete as well. Here’s a couple of different examples

workflow.onComplete = {
    // OSC 1337 (iTerm2)
    sendTerminalNotification("iterm2", "Pipeline Completion", "iterm2")
    
    // OSC 9 (Terminal.app)
    sendTerminalNotification("osc9", "Pipeline Completion", "Terminal.app")
    
    // OSC 777 (some terminals)
    sendTerminalNotification("osc777", "Pipeline Completed", "some terminals")
}

Depends on what terminal you’re using for which sequence it looks for

Here’s what I ended up with personally:

workflow.onComplete = {
    def currentTime = new Date()
    def formattedTime = currentTime.format("yyyy-MM-dd HH:mm:ss")

    sendTerminalNotification("osc9", 
        "Nextflow Workflow Complete",
        formattedTime,
    )
}

4 Likes

Really cool, any idea if this is Ghostty specific or might work with another terminal emulator. Willing to try if you think it might work!

EDIT: Just saw there are more terminals in your post lol, should have read before commenting

EDIT2: After a bit of looking around, I feel alacritty might not support this, if someone knows how to make it work, lmk!

No luck it looks like :disappointed: osc notification support · Issue #7105 · alacritty/alacritty · GitHub

You might try out Kitty or Wezterm. They have a similar speed and experience, but support the exitcodes. You could also use a notify script, but that depends on your OS.