This shell script retrieves, and reports on, the battery status of Apple peripheral devices such as the Magic Mouse, Keyboard and Trackpad. This allows devices to be charged timely, during downtime.
The status is printed to and a system notification is thrown below a chosen battery percentage threshold.
Tested on MacOS Big Sur. Might work on other releases.
- Move scheduling from cron to launchd
- Only report when battery status changed
- Make script self-updating on run
- Move todo to GitHub project boards
./report-peripheral-battery [battery-percentage-threshold]
With [battery-percentage-threshold]
an optional battery percentage treshold. Run without any arguments to use and see the default.
Make the project files accessible to all users of a machine by placing it in /Users/Shared
. For a single user; a more limited location such as ~/Applications can be used.
By making a shallow clone of the git repository (using --depth 1
), only the most recent changes are downloaded.
git clone --depth 1 https://github.com/averstuyf/av-tool-report-peripheral-battery.git /Users/Shared/av-tool-report-peripheral-battery/
Make a symlink to the launchd agent config file in /Library/LaunchAgents
for all users or ~/Library/LaunchAgents
for a specific user.
sudo ln -s /Users/Shared/av-tool-report-peripheral-battery/com.av.report-peripheral-battery.plist /Library/LaunchAgents/com.av.report-peripheral-battery.plist
Have launchd load the agent.
launchctl load /Library/LaunchAgents/com.av.report-peripheral-battery.plist
See script output and errors.
cat /tmp/report-peripheral-battery.stdout
cat /tmp/report-peripheral-battery.stderr
- Get low battery notifications for mouse earlier - Stack Exchange
This repository is licensed under the permissive MIT License.
Copyright (c) 2020 Arnaud Verstuyf