summary refs log tree commit diff stats
path: root/notification/notify_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'notification/notify_darwin.go')
-rw-r--r--notification/notify_darwin.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/notification/notify_darwin.go b/notification/notify_darwin.go
new file mode 100644
index 0000000..bddaf9e
--- /dev/null
+++ b/notification/notify_darwin.go
@@ -0,0 +1,25 @@
+// +build darwin
+
+package notification
+
+import (
+	"fmt"
+	"os/exec"
+	"strconv"
+)
+
+// Notify sends a desktop notification to the user using osascript. It
+// handles information in the form of Notif struct. It returns an
+// error (if exists).
+func (n Notif) Notify() error {
+	// This script cuts out parts of notification, this bug was
+	// confirmed on macOS Catalina 10.15.3, fix not yet known.
+	err := exec.Command("osascript", "-e",
+		`display notification `+strconv.Quote(n.Message)+` with title `+strconv.Quote(n.Title)).Run()
+	if err != nil {
+		err = fmt.Errorf("%s\n%s",
+			"notify_darwin.go: failed to sent notification with osascript",
+			err.Error())
+	}
+	return err
+}