{"id":13366529,"url":"https://github.com/deckarep/Gosx-notifier","last_synced_at":"2025-03-12T18:31:03.006Z","repository":{"id":12090001,"uuid":"14678125","full_name":"deckarep/gosx-notifier","owner":"deckarep","description":"gosx-notifier is a Go framework for sending desktop notifications to OSX 10.8 or higher","archived":false,"fork":false,"pushed_at":"2020-02-27T22:42:57.000Z","size":1831,"stargazers_count":588,"open_issues_count":11,"forks_count":52,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-10-25T05:22:41.662Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deckarep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-25T06:35:16.000Z","updated_at":"2024-09-21T18:11:18.000Z","dependencies_parsed_at":"2022-09-14T00:20:43.552Z","dependency_job_id":null,"html_url":"https://github.com/deckarep/gosx-notifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deckarep%2Fgosx-notifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deckarep%2Fgosx-notifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deckarep%2Fgosx-notifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deckarep%2Fgosx-notifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deckarep","download_url":"https://codeload.github.com/deckarep/gosx-notifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243271194,"owners_count":20264410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T00:01:26.421Z","updated_at":"2025-03-12T18:31:02.988Z","avatar_url":"https://github.com/deckarep.png","language":"Go","funding_links":[],"categories":["GUI"],"sub_categories":["高级控制台界面","高級控制台界面"],"readme":"gosx-notifier\n===========================\nA [Go](http://golang.org) lib for sending desktop notifications to OSX Mountain Lion's (10.8 or higher REQUIRED)\n[Notification Center](http://www.macworld.com/article/1165411/mountain_lion_hands_on_with_notification_center.html).\n\n[![GoDoc](http://godoc.org/github.com/deckarep/gosx-notifier?status.png)](http://godoc.org/github.com/deckarep/gosx-notifier)\n\nUpdate 4/3/2014\n------\nOn OSX 10.9 and above gosx-notifier now supports images and icons.\n![Now with custom icon support](../master/example.png?raw=true)\n\nSynopsis\n--------\nOSX Mountain Lion comes packaged with a built-in notification center. For whatever reason, [Apple sandboxed the\nnotification center API](http://forums.macrumors.com/showthread.php?t=1403807) to apps hosted in its App Store. The end\nresult? A potentially useful API shackled to Apple's ecosystem.\n\nThankfully, [Eloy Durán](https://github.com/alloy) put together [an osx app](https://github.com/alloy/terminal-notifier) that allows terminal access to the sandboxed API. **gosx-notifier** embeds this app with a simple interface to the closed API.\n\nIt's not perfect, and the implementor will quickly notice its limitations. However, it's a start and any pull requests are accepted and encouraged!\n\nDependencies:\n-------------\nThere are none! If you utilize this package and create a binary executable it will auto-magically install the terminal-notifier component into a temp directory of the server.  This is possible because in this latest version the terminal-notifier binary is now statically embedded into the Go source files.\n\n\nInstallation and Requirements\n-----------------------------\nThe following command will install the notification api for Go along with the binaries.  Also, utilizing this lib requires OSX 10.8 or higher. It will simply not work on lower versions of OSX.\n\n```sh\ngo get github.com/deckarep/gosx-notifier\n```\n\nUsing the Command Line\n-------------\n```Go\nnotify \"Wow! A notification!!!\"\n```\n\nuseful for knowing when long running commands finish\n\n```Go\nlongRunningCommand \u0026\u0026 notify done!\n```\n\nUsing the Code\n------------------\nIt's a pretty straightforward API:\n\n```Go\npackage main\n\nimport (\n    \"github.com/deckarep/gosx-notifier\"\n    \"log\"\n)\n\nfunc main() {\n    //At a minimum specifiy a message to display to end-user.\n    note := gosxnotifier.NewNotification(\"Check your Apple Stock!\")\n\n    //Optionally, set a title\n    note.Title = \"It's money making time 💰\"\n\n    //Optionally, set a subtitle\n    note.Subtitle = \"My subtitle\"\n\n    //Optionally, set a sound from a predefined set.\n    note.Sound = gosxnotifier.Basso\n\n    //Optionally, set a group which ensures only one notification is ever shown replacing previous notification of same group id.\n    note.Group = \"com.unique.yourapp.identifier\"\n\n    //Optionally, set a sender (Notification will now use the Safari icon)\n    note.Sender = \"com.apple.Safari\"\n\n    //Optionally, specifiy a url or bundleid to open should the notification be\n    //clicked.\n    note.Link = \"http://www.yahoo.com\" //or BundleID like: com.apple.Terminal\n\n    //Optionally, an app icon (10.9+ ONLY)\n    note.AppIcon = \"gopher.png\"\n\n    //Optionally, a content image (10.9+ ONLY)\n    note.ContentImage = \"gopher.png\"\n\n    //Then, push the notification\n    err := note.Push()\n\n    //If necessary, check error\n    if err != nil {\n        log.Println(\"Uh oh!\")\n    }\n}\n```\n\nSample App: Desktop Pinger Notification - monitors your websites and will notifiy you when a website is down.\n```Go\npackage main\n\nimport (\n\t\"github.com/deckarep/gosx-notifier\"\n\t\"net/http\"\n\t\"strings\"\n\t\"time\"\n)\n\n//a slice of string sites that you are interested in watching\nvar sites []string = []string{\n\t\"http://www.yahoo.com\",\n\t\"http://www.google.com\",\n\t\"http://www.bing.com\"}\n\nfunc main() {\n\tch := make(chan string)\n\n\tfor _, s := range sites {\n\t\tgo pinger(ch, s)\n\t}\n\n\tfor {\n\t\tselect {\n\t\tcase result := \u003c-ch:\n\t\t\tif strings.HasPrefix(result, \"-\") {\n\t\t\t\ts := strings.Trim(result, \"-\")\n\t\t\t\tshowNotification(\"Urgent, can't ping website: \" + s)\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc showNotification(message string) {\n\n\tnote := gosxnotifier.NewNotification(message)\n\tnote.Title = \"Site Down\"\n\tnote.Sound = gosxnotifier.Default\n\n\tnote.Push()\n}\n\n//Prefixing a site with a + means it's up, while - means it's down\nfunc pinger(ch chan string, site string) {\n\tfor {\n\t\tres, err := http.Get(site)\n\n\t\tif err != nil {\n\t\t\tch \u003c- \"-\" + site\n\t\t} else {\n\t\t\tif res.StatusCode != 200 {\n\t\t\t\tch \u003c- \"-\" + site\n\t\t\t} else {\n\t\t\t\tch \u003c- \"+\" + site\n\t\t\t}\n\t\t\tres.Body.Close()\n\t\t}\n\t\ttime.Sleep(30 * time.Second)\n\t}\n}\n```\n\nUsage Ideas\n-----------\n* Monitor your awesome server cluster and push notifications when something goes haywire (we've all been there)\n* Scrape Hacker News looking for articles of certain keywords and push a notification\n* Monitor your stock performance, push a notification, before you lose all your money\n* Hook it up to ifttt.com and push a notification when your motion-sensor at home goes off\n\nComing Soon\n-----------\n* Remove ID\n\nLicence\n-------\nThis project is dual licensed under [any licensing defined by the underlying apps](https://github.com/alloy/terminal-notifier) and MIT licensed for this version written in Go.\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/deckarep/gosx-notifier/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeckarep%2FGosx-notifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeckarep%2FGosx-notifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeckarep%2FGosx-notifier/lists"}