Linux命令行连接蓝牙鼠标

#!/bin/bash

# enable bluetooth
# systemctl start bluetooth
# sleep 1

# run the program bluez
echo -e 'connect EE:B4:FE:39:27:AC\nversion\nlist\nshow\ndevices\npaired-devices\nquit' | bluetoothctl

有一款蓝牙鼠标在断开后,必须 长按 鼠标底部的 配对键 3秒, PC才可通过蓝牙控制器 扫描到 鼠标设置

用 empty 解决延时的问题

#!/bin/bash

empty -f -L /dev/shm/empty.log -i /dev/shm/empty.in -o /dev/shm/empty.out bluetoothctl

if [ $? = 0 ]; then
	if [ -w $fifo_in -a -r $fifo_out ]; then
		empty -w -v -i /dev/shm/empty.out -o /dev/shm/empty.in -t 1 "Mouse" "connect EE:B4:FE:39:27:AC\n"
		#sleep 1
		#empty -s -o /dev/shm/empty.in "connect EE:B4:FE:39:27:AC\n"
		sleep 3
		cat /dev/shm/empty.log
		rm /dev/shm/empty.log
	fi
else
	echo 'failed to start bluectrl'
fi