prashantgupta24 / mac-sleep-notifier

macOS Sleep/ Wake notifications in golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mentioned in Awesome Go Go Report Card codecov version godoc-badge

macOS Sleep/ Wake notifications in golang

Inspired from this 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

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

About

macOS Sleep/ Wake notifications in golang

License:MIT License


Languages

Language:Go 64.6%Language:C++ 29.9%Language:Makefile 5.5%