日期: 2025-4-12
# 安装必要的包 sudo apt install -y bluetooth bluez bluez-tools rfkill pulseaudio pulseaudio-module-bluetooth pavucontrol # 启用蓝牙服务开机自启 sudo systemctl enable bluetooth # 确保配置文件包含正确设置 sudo nano /etc/bluetooth/main.conf
在main.conf中确保有以下配置:
[General] Enable=Source,Sink,Media,Socket
# 进入蓝牙控制台 bluetoothctl # 在bluetoothctl中执行: power on connect 08:F0:B6:C5:02:A6 # 替换为你的耳机MAC地址
# 在bluetoothctl中执行: power on scan on pair 08:F0:B6:C5:02:A6 trust 08:F0:B6:C5:02:A6 connect 08:F0:B6:C5:02:A6
# 播放测试音频 aplay /usr/share/sounds/alsa/Front_Center.wav
# 如果听不到声音,重启音频服务 pulseaudio -k pulseaudio --start # 检查蓝牙服务状态 sudo systemctl status bluetooth # 如果蓝牙被阻止 rfkill list sudo rfkill unblock bluetooth
# 创建脚本 nano ~/connect_headphone.sh
在脚本中写入:
#!/bin/bash echo "power on" | bluetoothctl echo "connect 08:F0:B6:C5:02:A6" | bluetoothctl
设置脚本权限:
chmod +x ~/connect_headphone.sh
之后只需运行:
~/connect_headphone.sh
# 创建配置文件 nano ~/.config/bluetooth/devices.conf
添加内容:
[Devices] headphone=08:F0:B6:C5:02:A6