I would like to be able to pair my laptop and my phone without having to manually accept the pair request on my phone. Is this possible?
Once paired, it should not unpair at all. I paired my phone just once, then I made a script which will connect/disconnect it (I have another to switch from discrete channels to quadrophonic/stereo, so I press both to listen to podcasts).
#!/bin/bash
# For toggling A15 Bluetooth connection with KDE Plasma notifications
DEVICE_MAC="08:A5:DF:D7:41:36"
DEVICE_NAME="Samsung A15"
CONNECT_SOUND="/home/ben/Audio/Sounds/phone-connect.ogg"
DISCONNECT_SOUND="/home/ben/Audio/Sounds/phone-disconnect.ogg"
# Function to get the current system volume
get_current_volume() {
amixer get Master | grep -oP '\[\d+%\]' | head -n 1 | tr -d '[]%'
}
# Function to show KDE notification
notify() {
local title="$1"
local message="$2"
notify-send -u normal -i "audio-volume-high" "$title" "$message"
}
# Function to check if the device is connected
is_device_connected() {
bluetoothctl info "$DEVICE_MAC" | grep -q "Connected: yes"
}
# Function to show KDE notification and play sound
notify() {
local title="$1"
local message="$2"
local sound="$3"
# Show KDE notification
notify-send -u normal -i "bluetooth" "$title" "$message"
# Play sound if available
if [ -f "$sound" ]; then
paplay "$sound" &
fi
}
# Main script
if is_device_connected; then
echo "Device $DEVICE_NAME ($DEVICE_MAC) is connected. Disconnecting..."
disconnect_output=$(bluetoothctl disconnect "$DEVICE_MAC" 2>&1)
if ! is_device_connected; then
echo "Successfully disconnected."
notify "Bluetooth Disconnected" "Samsung A15 was disconnected" "$DISCONNECT_SOUND"
else
echo "Failed to disconnect: $disconnect_output" >&2
notify "Bluetooth Error" "Failed to disconnect Samsung A15 $DEVICE_NAME ($DEVICE_MAC)" "$DISCONNECT_SOUND"
exit 1
fi
else
echo "Device $DEVICE_NAME ($DEVICE_MAC) is not connected. Attempting to connect..."
notify "Bluetooth" "$DEVICE_NAME ($DEVICE_MAC) is not connected... Attempting to connect!" "$DISCONNECT_SOUND"
# Ensure Bluetooth is powered on
bluetoothctl power on >/dev/null 2>&1
# Try to connect
connect_output=$(bluetoothctl connect "$DEVICE_MAC" 2>&1)
if is_device_connected; then
# Get current volume
current_volume=$(get_current_volume)
# Get current volume
current_volume=$(get_current_volume)
# Set volume to 45%
amixer set Master 45%
# Send a single notification with the current and new volume levels
notify "Volume Adjusted" "from $current_volume% to 45%."
echo "Successfully connected."
notify "Bluetooth Connected" "Samsung A15 was connected" "$CONNECT_SOUND"
else
echo "Failed to connect: $connect_output" >&2
notify "Bluetooth Error" "Failed to connect to $DEVICE_NAME ($DEVICE_MAC)" "$DISCONNECT_SOUND"
exit 1
fi
fi
exit 0
Then when I am taking my phone out of the room, I just hit the shortcuts again to return audio to the phone.