pmset

package module
v0.0.0-...-6ea0307 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2018 License: MIT Imports: 3 Imported by: 2

README

go-pmset

Golang library to access OSX's system assertions, the ones displayed when you run pmset -g assertions

Installation

go-pmset requires OS X.

go get github.com/caseymrm/go-pmset

Documentation

https://godoc.org/github.com/caseymrm/go-pmset

Examples

GetAssertions()
package main

import (
    "encoding/json"
    "log"
    
    "github.com/caseymrm/go-pmset"
)

func main() {
    a := pmset.GetAssertions()
    b, _ := json.MarshalIndent(a, "", "  ")
    log.Printf("%s\n", b)
}
2018/04/17 16:11:23 
{
  "ApplePushServiceTask": 0,
  "AwakeOnReservePower": 0,
  "BackgroundTask": 0,
  "CPUBoundAssertion": 0,
  "ChargeInhibit": 0,
  "DisableInflow": 0,
  "DisableLowPowerBatteryWarnings": 0,
  "DisplayWake": 0,
  "EnableIdleSleep": 1,
  "ExternalMedia": 0,
  "InteractivePushServiceTask": 0,
  "InternalPreventDisplaySleep": 1,
  "InternalPreventSleep": 0,
  "NetworkClientActive": 0,
  "PreventDiskIdle": 0,
  "PreventSystemSleep": 0,
  "PreventUserIdleDisplaySleep": 1,
  "PreventUserIdleSystemSleep": 1,
  "SystemIsActive": 0,
  "UserIsActive": 1
}
GetPIDAssertions()
package main

import (
    "encoding/json"
    "log"
    
    "github.com/caseymrm/go-pmset"
)

func main() {
    a := pmset.GetPIDAssertions()
    b, _ := json.MarshalIndent(a, "", "  ")
    log.Printf("%s\n", b)
}
2018/04/17 16:11:23 {
  "PreventUserIdleDisplaySleep": [
    {
      "PID": 47784,
      "Name": "com.apple.WebCore: HTMLMediaElement playback"
    }
  ],
  "PreventUserIdleSystemSleep": [
    {
      "PID": 180,
      "Name": "com.apple.audio.AppleUSBAudioEngine:C-Media Electronics Inc.:USB Audio Device:14131000:2,1.context.preventuseridlesleep"
    },
    {
      "PID": 180,
      "Name": "com.apple.audio.AppleUSBAudioEngine:C-Media Electronics Inc.:USB Audio Device:14131000:2,1.context.preventuseridlesleep"
    }
  ],
  "UserIsActive": [
    {
      "PID": 114,
      "Name": "com.apple.iohideventsystem.queue.tickle.4294978958.17"
    }
  ]
}
SubscribeAssertionChanges()
SubscribeAssertionChangesAndRun()
package main

import (
    "encoding/json"
    "log"
    
    "github.com/caseymrm/go-pmset"
)

func main() {
	channel := make(chan AssertionChange)
	go func() {
		for change := range channel {
            b, _ := json.MarshalIndent(change, "", "  ")
            log.Printf("%s\n", b)
		}
	}()
	SubscribeAssertionChangesAndRun(channel)
}
2018/04/30 11:30:06 {
  "Action": "Released",
  "Type": "PreventUserIdleDisplaySleep",
  "Pid": {
    "PID": 47784,
    "Name": "com.apple.WebCore: HTMLMediaElement playback"
  }
}
2018/04/30 11:30:07 {
  "Action": "Created",
  "Type": "PreventUserIdleDisplaySleep",
  "Pid": {
    "PID": 47784,
    "Name": "com.apple.WebCore: HTMLMediaElement playback"
  }
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAssertions

func GetAssertions() map[string]int

GetAssertions returns a map of assertion keys to values

func GetPIDAssertions

func GetPIDAssertions() map[string][]PidAssertion

GetPIDAssertions returns a map of assertion keys to procceses holding those assertions

func GetThermalConditions

func GetThermalConditions() map[string]int

GetThermalConditions returns the current cpu limits

func SubscribeAssertionChanges

func SubscribeAssertionChanges(channel chan<- AssertionChange)

SubscribeAssertionChanges returns, changes come through the supplied channel once dispatch_main or nsapplication is run

func SubscribeAssertionChangesAndRun

func SubscribeAssertionChangesAndRun(channel chan<- AssertionChange)

SubscribeAssertionChangesAndRun does not return, changes come through the supplied channel

func SubscribeThermalChanges

func SubscribeThermalChanges(channel chan<- bool)

SubscribeThermalChanges returns, changes come through the supplied channel once dispatch_main or nsapplication is run

func SubscribeThermalChangesAndRun

func SubscribeThermalChangesAndRun(channel chan<- bool)

SubscribeThermalChangesAndRun does not return, changes come through the supplied channel

Types

type AssertionChange

type AssertionChange struct {
	Action string
	Type   string
	Pid    PidAssertion
}

AssertionChange represents a process making a change to an assertion

type PidAssertion

type PidAssertion struct {
	PID  int
	Name string
}

PidAssertion represents one process that has an assertion

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL