Created
July 30, 2018 12:30
-
-
Save mroach/d9870ceebe6b3d6f28d545b9717647e2 to your computer and use it in GitHub Desktop.
Logs Magic Trackpad 2 battery life to log file with timestamp
This file contains 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
#!/bin/bash | |
set -e | |
tmpfile="${TMPDIR}sys_bluetooth_$(date +%s).plist" | |
# dump data to temp plist file | |
/usr/sbin/system_profiler -xml SPBluetoothDataType > "$tmpfile" | |
# read battery percentage from tempfile and delete percent sign | |
batt=`/usr/libexec/PlistBuddy "$tmpfile" -c "Print 0:_items:0:device_title:0:'Magic Trackpad 2':device_batteryPercent" | tr -d '%'` | |
ts=$(date +"%F %T") | |
rm $tmpfile | |
echo "$ts,$batt" >> ~/mtp.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment