# osxsleep

> Allows to monitor macOS device sleep from Node

Latest version **0.4.6** (published 2017-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install osxsleep
pnpm add osxsleep
yarn add osxsleep
bun add osxsleep
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.6 |
| Published | 2017-05-16 |
| First published | 2017-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.30 <0.12 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 1 |
| Author | Milosz Derezynski |
| Maintainers | mderezynski |
| Keywords | device, power, osx, sleep |

## Links

- npm: https://www.npmjs.com/package/osxsleep
- Repository: https://github.com/md5555/osxsleep
- Homepage: https://github.com/md5555/osxsleep#readme
- Issues: https://github.com/md5555/osxsleep/issues
- npm.io page: https://npm.io/package/osxsleep

## Dependencies (3)

- [nan](https://npm.io/package/nan.md) ~2.3.2
- [bindings](https://npm.io/package/bindings.md) 1.2.1
- [node-abi](https://npm.io/package/node-abi.md) 2.0.0

## Recent versions

- 0.4.6 (latest) — 2017-05-16
- 0.4.5 — 2017-05-16
- 0.4.4 — 2017-05-16
- 0.4.3 — 2017-05-16
- 0.4.2 — 2017-05-16
- 0.4.1 — 2017-05-16
- 0.4.0 — 2017-05-16
- 0.3.0 — 2017-05-16
- 0.2.2 — 2017-05-13
- 0.2.1 — 2017-05-02
- 0.2.0 — 2017-05-02
- 0.1.1 — 2017-05-02
- 0.1.0 — 2017-05-02
- 0.0.3 — 2017-05-01
- 0.0.2 — 2017-05-01
- … 1 more at https://npm.io/package/osxsleep/versions

## README

## osxsleep

osxsleep allows to monitor macOS device's sleep state from Node; additionally, you can query the current power source.

Example usage:

```sh

  const osxsleep = require('osxsleep');
   
  ...

  var source = osxsleep.OSXSleep.getPowerSource();

  switch(source) {
	case osxsleep.POWER_SOURCE_AC:
		break;
	case osxsleep.POWER_SOURCE_BATTERY:
		break;
	case osxsleep.POWER_SOURCE_UPS:
		break;
  }

  ...
 
  osxsleep.OSXSleep.start(function(sleepstate){

	switch(sleepstate) {
		case osxsleep.CAN_SLEEP:
			if (/* can sleep */) {
			    return true;
			} else {
			    return false;
			}
			break;
		case osxsleep.WILL_SLEEP:
			break;
		case osxsleep.WILL_POWER_ON:
			break;
		case osxsleep.HAS_POWERED_ON:
			break;
	}
  });

  ...
  
  osxsleep.OSXSleep.stop();
 
```

It is *important* to call stop() in order to unregister the native IOKit sleep state monitor & resources!

---
_Source: https://npm.io/package/osxsleep · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
