This is a continuation of
Finally switched to Linux Mint (
https://cplusplus.com/forum/lounge/285724/).
Mint, by default, is constantly popping up notifications in the corner whenever my Bluetooth mouse connects and disconnects. It is kind of annoying, but I left them alone because they also reported the mouse’s battery status, which is useful.
But it did mean I have to regularly clear out the list of notifications for just the spam from the mouse connect/disconnect.
So I did this:
❶ Stop the obnoxious notifications
Right-click the Bluetooth icon in the Notification Tray, select “Plugins” and uncheck the “Connection Notifier”.
❷ Found which filename the
upower tool has assigned to my mouse:
% upower -e
/org/freedesktop/UPower/devices/mouse_dev_D7_80_86_CB_3C_9F
/org/freedesktop/UPower/devices/DisplayDevice
%
|
❸ Wrote a little Tcl script to check the battery status and post a notification if it is 30% or less.
I stuck it in my local bin directory, but it could have been put anywhere.
~/bin/check-mouse-battery
1 2 3 4 5 6 7 8 9 10 11
|
#! /usr/bin/env tclsh
set s [exec -ignorestderr -- upower -i /org/freedesktop/UPower/devices/mouse_dev_D7_80_86_CB_3C_9F]
regexp -- {percentage:\s+(\d+)%} $s - percentage
set percentage "1$percentage"
set percentage [expr {$percentage - 100}]
if {$percentage < 31} {
exec -ignorestderr -- notify-send "Mouse Battery" "Power level at ${percentage}%" --icon=dialog-info
}
|
❹ Added an hourly check for the battery status.
That might be overkill (daily might suffice), but getting a new battery in the mouse is something not to put off, so I figured this particular notification can be extra-annoying.
I also added the check to every time the PC starts.
To edit your user-local cron tasks, use the
crontab facility:
Chances are you will be creating a new user-local file, and crontab will tell you all about it, but ultimately you’ll get a blank file with a bunch of verbiage in #comments at the top. Ignore those and add the lines we want.
The first line just means to check at minute=0 of every hour of every day of every etc.
1 2 3 4
|
0 * * * * /home/michael/bin/check-mouse-battery
@reboot /home/michael/bin/check-mouse-battery
|
Saved, and done!
Oh, if you are unfamiliar with terminal text editors, choosing Nano is a pretty safe place to start. I prefer Vim, lol, but you can certainly choose another by assigning an editor environment variable: % EDITOR=gedit crontab -e
.
Now, whenever my mouse battery starts getting suspiciously low, I’ll get a useful popup notification telling me how much power it has left. At 30% it really means “change me now”, so that works.
I’m kinda pleased with myself. 🙂