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,
)
}