From f637ca23d4aa1da2d297356a4173564c194839d0 Mon Sep 17 00:00:00 2001 From: gutmet Date: Sun, 13 Jan 2019 10:24:46 +0100 Subject: [PATCH] add desktop notifications --- goutil.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/goutil.go b/goutil.go index 2530045..99a5a6d 100644 --- a/goutil.go +++ b/goutil.go @@ -293,3 +293,20 @@ func Execute(possibleCommands []Command) error { return cmd.exec(os.Args[2:]) } } + +func Notify(head string, body string) error { + var cmd *exec.Cmd + goos := runtime.GOOS + switch goos { + case "windows": + cmd = nil + case "darwin": + cmd = exec.Command("osascript", "-e", `display notification "`+body+`" with title "`+head+`"`) + default: + cmd = exec.Command("notify-send", head, body) + } + if cmd != nil { + return cmd.Start() + } + return nil +}