Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prashantgupta24/mac-sleep-notifier
macOS Sleep/ Wake notifications in golang
https://github.com/prashantgupta24/mac-sleep-notifier
c cgo golang macos sleep
Last synced: 14 days ago
JSON representation
macOS Sleep/ Wake notifications in golang
- Host: GitHub
- URL: https://github.com/prashantgupta24/mac-sleep-notifier
- Owner: prashantgupta24
- License: mit
- Created: 2019-03-30T00:43:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T15:59:38.000Z (over 5 years ago)
- Last Synced: 2024-07-31T20:51:56.947Z (3 months ago)
- Topics: c, cgo, golang, macos, sleep
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 32
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - mac-sleep-notifier - OSX Sleep/Wake notifications in golang. (GUI / Search and Analytic Databases)
README
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![Go Report Card](https://goreportcard.com/badge/github.com/prashantgupta24/mac-sleep-notifier)](https://goreportcard.com/report/github.com/prashantgupta24/mac-sleep-notifier) [![codecov](https://codecov.io/gh/prashantgupta24/mac-sleep-notifier/branch/master/graph/badge.svg)](https://codecov.io/gh/prashantgupta24/mac-sleep-notifier) [![version][version-badge]][RELEASES] [![godoc-badge][godoc-badge]][godoc-link]
## macOS Sleep/ Wake notifications in golang
Inspired from [this](https://nicolai86.eu/blog/2017/12/sleep-wake-notifications-in-go/) blog.
This libary notifies through a channel whenever your machine is put to sleep or is woken up. Calling the `Start` function will get you a channel on which you receive both `Sleep` and `Awake` activities.
## Installation
`go get -u github.com/prashantgupta24/mac-sleep-notifier/notifier`
## Usage
```go
notifierCh := notifier.GetInstance().Start()for {
select {
case activity := <-notifierCh:
if activity.Type == notifier.Awake {
log.Println("machine awake")
} else {
if activity.Type == notifier.Sleep {
log.Println("machine sleeping")
}
}
}
}
```
## Example
See example [here](https://github.com/prashantgupta24/mac-sleep-notifier/blob/master/example/example.go)[godoc-badge]: https://img.shields.io/badge/godoc-reference-blue.svg
[godoc-link]: https://godoc.org/github.com/prashantgupta24/mac-sleep-notifier/notifier[version-badge]: https://img.shields.io/github/release/prashantgupta24/mac-sleep-notifier.svg
[RELEASES]: https://github.com/prashantgupta24/mac-sleep-notifier/releases