Skip to content

Instantly share code, notes, and snippets.

@mroach
Created July 30, 2018 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mroach/d9870ceebe6b3d6f28d545b9717647e2 to your computer and use it in GitHub Desktop.
Save mroach/d9870ceebe6b3d6f28d545b9717647e2 to your computer and use it in GitHub Desktop.
Logs Magic Trackpad 2 battery life to log file with timestamp
#!/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