Learn how to block annoying bluetooth notifications from specific devices on Linux using the ConnectionNotifier plugin and a simple script.
Table of Contents
- Problem
- What is the ConnectionNotifier plugin?
- How to block bluetooth notifications from specific devices on Linux?
- Frequently Asked Questions (FAQs)
- Question: How can I stop all bluetooth notifications on Linux?
- Question: How can I enable bluetooth notifications on Linux?
- Question: How can I customize the bluetooth notifications on Linux?
- Summary
Problem
Sometimes you may receive unwanted bluetooth notifications from devices that are not yours, such as your neighbors’ machines or other nearby devices. These notifications can be distracting and annoying, especially if they happen frequently. In this article, we will show you how to block bluetooth notifications from specific devices on Linux using the ConnectionNotifier plugin and a simple script.
What is the ConnectionNotifier plugin?
The ConnectionNotifier plugin is a component of the blueman-applet, which is a graphical user interface for managing bluetooth devices on Linux. The ConnectionNotifier plugin is responsible for displaying notifications when a bluetooth device connects or disconnects to your computer. You can enable or disable this plugin from the Bluetooth window by clicking on View -> Plugins and checking or unchecking the ConnectionNotifier plugin on the left.
How to block bluetooth notifications from specific devices on Linux?
If you want to block bluetooth notifications from specific devices on Linux, you can use a simple script that filters the notifications based on the name of the connecting device. The script uses the dbus-monitor command to listen for bluetooth events and the notify-send command to display notifications. The script also uses a regular expression to match the name of the device that you want to block. For example, if you want to block all devices whose name starts with MWAI, you can use the regular expression ^MWAI.
Here is the script:
#!/bin/bash
# Block bluetooth notifications from specific devices on Linux
# Change the regex below to match the name of the device you want to block
regex="^MWAI"
# Listen for bluetooth events using dbus-monitor
dbus-monitor --system "type='signal',interface='org.bluez.Device1',member='PropertiesChanged'" |
while read -r line; do
# Check if the line contains the device name
if [[ $line == *"Name"* ]]; then
# Extract the device name from the line
name=$(echo $line | cut -d '"' -f 4)
# Check if the device name matches the regex
if [[ $name =~ $regex ]]; then
# If yes, set a flag to block the notification
block=1
else
# If no, set a flag to allow the notification
block=0
fi
fi
# Check if the line contains the connected status
if [[ $line == *"Connected"* ]]; then
# Extract the connected status from the line
status=$(echo $line | cut -d ' ' -f 5 | tr -d ',')
# Check if the flag is set to block the notification
if [[ $block -eq 1 ]]; then
# If yes, do nothing
:
else
# If no, display the notification using notify-send
if [[ $status -eq 1 ]]; then
notify-send "Bluetooth" "$name connected"
else
notify-send "Bluetooth" "$name disconnected"
fi
fi
fi
done
To use the script, you need to do the following steps:
1. Save the script as a file, such as block-bt.sh, and make it executable with the command:
chmod +x block-bt.sh
2. Change the regex variable in the script to match the name of the device you want to block. For example, if you want to block all devices whose name contains the word Phone, you can use the regex Phone.
3. Run the script in the background with the command:
./block-bt.sh &
4. Optionally, you can add the script to your startup applications, so that it runs automatically when you log in.
Frequently Asked Questions (FAQs)
Question: How can I stop all bluetooth notifications on Linux?
Answer: You can stop all bluetooth notifications on Linux by disabling the ConnectionNotifier plugin from the Bluetooth window. Alternatively, you can use the following commands to disable the plugin from the terminal:
gsettings set org.gnome.nm-applet disable-disconnected-notifications "true"
gsettings set org.gnome.nm-applet disable-connected-notifications "true"
Question: How can I enable bluetooth notifications on Linux?
Answer: You can enable bluetooth notifications on Linux by enabling the ConnectionNotifier plugin from the Bluetooth window. Alternatively, you can use the following commands to enable the plugin from the terminal:
gsettings set org.gnome.nm-applet disable-disconnected-notifications "false"
gsettings set org.gnome.nm-applet disable-connected-notifications "false"
Question: How can I customize the bluetooth notifications on Linux?
Answer: You can customize the bluetooth notifications on Linux by editing the script and changing the notify-send command. For example, you can add an icon, a timeout, or a sound to the notification. For more options, see the notify-send man page.
Summary
In this article, we have shown you how to block bluetooth notifications from specific devices on Linux using the ConnectionNotifier plugin and a simple script. This can help you avoid unwanted and annoying notifications from devices that are not yours. We hope you found this article useful and informative. If you have any questions or feedback, please leave a comment below.
Disclaimer: The author is not responsible for any errors or omissions in this article. The user is advised to verify the accuracy and validity of the information before applying it. The user is also responsible for any consequences or damages that may arise from using the information in this article. The author does not endorse or recommend any products or services mentioned in this article.