Created
November 3, 2025 16:30
-
-
Save mkatychev/80356d5fc73f585d8281a5f9b634389d to your computer and use it in GitHub Desktop.
Hibernate mode toggle macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def hmode [] { | |
| let entry = pmget | where setting == "hibernatemode" | |
| let name = match ($entry.mode.0 | into int) { | |
| 3 => "off" | |
| 25 => "on" | |
| 0 => "hard" | |
| $n => $n | |
| } | |
| {hibernate: $name } | |
| } | |
| def pmget []: nothing -> table { | |
| pmset -g | parse ' {setting} {mode}' | update mode { str trim } | |
| } | |
| def hibernate-cmp [] { | |
| [ | |
| [value description]; | |
| [ hard "The system will not back memory up to persistent storage." ] | |
| [ on "The system will write memory to disk and remove power to memory."] | |
| [ off "The system will write memory to disk and power memory during sleep."] | |
| ] | |
| } | |
| export def hibernate [mode?: string@hibernate-cmp]: nothing -> record { | |
| let mode = match $mode { | |
| off | 3 => 3 | |
| on | 25 => 25 | |
| hard | 0 => 0 | |
| null => { | |
| return (hmode) | |
| } | |
| } | |
| sudo pmset hibernatemode $mode | |
| hmode | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment