Skip to content

Instantly share code, notes, and snippets.

@luckman212
Created May 3, 2024 13:56
Show Gist options
  • Save luckman212/a46f62f247bfcf46ba03faf83f3b88cb to your computer and use it in GitHub Desktop.
Save luckman212/a46f62f247bfcf46ba03faf83f3b88cb to your computer and use it in GitHub Desktop.
poor man's uptime on macOS by parsing JSON output of system_profiler
system_profiler SPSoftwareDataType -json |
jq --raw-output --argjson labels '[ "day", "hour", "minute", "second" ]' '
.SPSoftwareDataType[0].uptime[3:] // empty | split(":") as $uptime |
def pprint:
($uptime[.] | tonumber) as $val |
if $val == 0 then empty else
"\($val) \($labels[.])" + (if $val == 1 then "" else "s" end)
end;
[range($uptime|length)] | map(pprint) | join(", ")'
@luckman212
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment