40 lines
695 B
Go
40 lines
695 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"howett.net/plist"
|
|
)
|
|
|
|
type ioregRoot struct {
|
|
IOConsoleUsers []struct {
|
|
UID int `plist:"kCGSSessionUserIDKey"`
|
|
Locked bool `plist:"CGSSessionScreenIsLocked"`
|
|
} `plist:"IOConsoleUsers"`
|
|
}
|
|
|
|
func screenCmd() {
|
|
out, err := exec.Command("ioreg", "-n", "Root", "-d1", "-a").Output()
|
|
if err != nil {
|
|
fatal("ioreg", "err", err)
|
|
}
|
|
root := ioregRoot{}
|
|
_, err = plist.Unmarshal(out, &root)
|
|
if err != nil {
|
|
fatal("decode ioreg", "err", err)
|
|
}
|
|
state := "no-session"
|
|
for _, u := range root.IOConsoleUsers {
|
|
if u.UID != os.Getuid() {
|
|
continue
|
|
}
|
|
state = "unlocked"
|
|
if u.Locked {
|
|
state = "locked"
|
|
}
|
|
}
|
|
fmt.Println(state)
|
|
}
|