Skip to content

Instantly share code, notes, and snippets.

@selfagency
Last active July 11, 2021 00:58
Show Gist options
  • Save selfagency/3defeb12a0df124da141652b5895fca5 to your computer and use it in GitHub Desktop.
Save selfagency/3defeb12a0df124da141652b5895fca5 to your computer and use it in GitHub Desktop.
[parse apple ioreg command output]
#!/usr/bin/env bash
function parseData() {
tail -n +2 $1 |
sed -re 's/\=/\:/g' |
sed -re 's/</\"/g' |
sed -re 's/>/\"/g' |
sed -re 's/No/false/g' |
sed -re 's/Yes/true/g' |
sed -re 's/\(/\[/g' |
sed -re 's/\)/\]/g' |
sed '$d' |
sed '$d' |
sed 's/$/,/' |
sed '1 s/\,//' |
sed '$ s/\,//' |
sed '52 s/,//'
}
ioreg -r -c "AppleSmartBattery" | parseData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment