├── .gitignore ├── sample.png ├── go.mod ├── go.sum ├── README.md ├── main.go └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wobsoriano/go-mac-notifier/HEAD/sample.png -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/wobsoriano/go-mac-notifier 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/wobsoriano/go-jxa v0.1.1 7 | github.com/wobsoriano/go-macos-version v0.1.2 8 | ) 9 | 10 | require github.com/Masterminds/semver v1.5.0 // indirect 11 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= 2 | github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= 3 | github.com/wobsoriano/go-jxa v0.1.1 h1:VY+ulIVMiCAhSiC4PNXs2y9YDK/i67StR7stQNdyXcY= 4 | github.com/wobsoriano/go-jxa v0.1.1/go.mod h1:a7SNkng5zQnaCD59C93XkPh5A6gAL/T5nhxHOhmjufk= 5 | github.com/wobsoriano/go-macos-version v0.1.2 h1:f5P0X2dqMOoRONkTSUPbAQ6YV2N3SOmJwErdrr3EiCI= 6 | github.com/wobsoriano/go-macos-version v0.1.2/go.mod h1:jpf39fsNzfivDuSyvPPLYUSOCj0gkt3JQJCUw4vrXoU= 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-mac-notifier 2 | 3 | Send desktop notifications to OSX 10.9 or higher. 4 | 5 | ![](sample.png) 6 | 7 | ## Install 8 | 9 | ```bash 10 | $ go get github.com/wobsoriano/go-mac-notifier 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```go 16 | package main 17 | 18 | import ( 19 | "log" 20 | 21 | "github.com/wobsoriano/go-mac-notifier" 22 | ) 23 | 24 | func main() { 25 | options := notifierOptions{ 26 | title: "News", 27 | text: "You are amazing.", 28 | subtitle: "My subtitle", 29 | sound: "Hero", // Check ~/Library/Sounds or /System/Library/Sounds for available sounds 30 | } 31 | 32 | err := notifier.DisplayNotification(options) 33 | } 34 | ``` 35 | 36 | ## License 37 | 38 | MIT 39 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package notifier 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | 7 | "github.com/wobsoriano/go-jxa" 8 | version "github.com/wobsoriano/go-macos-version" 9 | ) 10 | 11 | type notifierOptions struct { 12 | title string 13 | text string 14 | subtitle string 15 | sound string 16 | } 17 | 18 | func DisplayNotification(n notifierOptions) error { 19 | version.AssertMacOSVersion(">=10.9") 20 | 21 | if len(n.title) == 0 || len(n.text) == 0 { 22 | return errors.New("title or text is required") 23 | } 24 | 25 | _, err := jxa.RunJXA(fmt.Sprintf(` 26 | const app = Application.currentApplication() 27 | 28 | app.includeStandardAdditions = true 29 | 30 | app.displayNotification("%s", { 31 | withTitle: "%s", 32 | subtitle: "%s", 33 | soundName: "%s" 34 | }) 35 | `, n.text, n.title, n.subtitle, n.sound)) 36 | 37 | return err 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Robert Soriano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------