여러 맥북간 트랙패드 블루투스 페어링 – 코드로 전환 하기

맥북간 트랙패드 블루투스 페어링 – 코드로 전환하기

애플 매직 트랙패드는 하나인데 여러 맥북간 페어링 전환을 해야 하는 경우, 번거로움을 감수할 수 밖에 없습니다.

트랙패드 자체가 멀티 페어링을 지원하지 않기 때문에 이런 어려움이 생기는데요. 동봉된 케이블을 꼽는 것만으로 페어링이 쉽다고 할 수 있겠으나, 코드를 매번 챙기는 것도 일이거니와 이제 애플 생태계도 라이트닝을 버리고 USB-C로 옮겨가고 있지 않습니까? 따라서, 별도의 라이트닝 케이블을 확보해야 하는 것도 스트레스입니다.

코드로 페어링 전환을 좀더 편리하게 할 수는 없을까요?

유사한 상용 프로그램도 있는 마당에, 직접 도전해 봅시다.

사전 준비

내 맥북에 어떤 블루투스 장비들이 있는지 확인해 보기 위한 툴이 필요합니다.

blueutil 이라는 녀석을 먼저 설치합니다. $ brew install blueutil

blueutil을 설치했다면, blueutil로 할 수 있는 작업을 확인해 봅니다.

$ blueutil --help

blueutil v2.9.1

Usage:
blueutil [options]

Without options outputs current state

-p, --power output power state as 1 or 0
-p, --power STATE set power state
-d, --discoverable output discoverable state as 1 or 0
-d, --discoverable STATE set discoverable state

--favourites, --favorites
list favourite devices
--inquiry [T] inquiry devices in range, 10 seconds duration by default excluding time for name updates
--paired list paired devices
--recent [N] list recently used devices, 10 by default, 0 to list all
--connected list connected devices

--info ID show information about device
--is-connected ID connected state of device as 1 or 0
--connect ID create a connection to device
--disconnect ID close the connection to device
--pair ID [PIN] pair with device, optional PIN of up to 16 characters will be used instead of interactive input if requested in specific pair mode
--unpair ID EXPERIMENTAL unpair the device
--add-favourite ID, --add-favorite ID
add to favourites
--remove-favourite ID, --remove-favorite ID
remove from favourites

--format FORMAT change output format of info and all listing commands

--wait-connect ID [TIMEOUT]
EXPERIMENTAL wait for device to connect
--wait-disconnect ID [TIMEOUT]
EXPERIMENTAL wait for device to disconnect
--wait-rssi ID OP VALUE [PERIOD [TIMEOUT]]
EXPERIMENTAL wait for device RSSI value which is 0 for golden range, -129 if it cannot be read (e.g. device is disconnected)

-h, --help this help
-v, --version show version

STATE can be one of: 1, on, 0, off, toggle
ID can be either address in form xxxxxxxxxxxx, xx-xx-xx-xx-xx-xx or xx:xx:xx:xx:xx:xx, or name of device to search in used devices
OP can be one of: >, >=, <, <=, =, !=; or equivalents: gt, ge, lt, le, eq, ne
PERIOD is in seconds, defaults to 1
TIMEOUT is in seconds, default value 0 doesn't add timeout
FORMAT can be one of:
default - human readable text output not intended for consumption by scripts
new-default - human readable comma separated key-value pairs (EXPERIMENTAL, THE BEHAVIOUR MAY CHANGE)
json - compact JSON
json-pretty - pretty printed JSON

Due to possible problems, blueutil will refuse to run as root user (see https://github.com/toy/blueutil/issues/41).
Use environment variable BLUEUTIL_ALLOW_ROOT=1 to override (sudo BLUEUTIL_ALLOW_ROOT=1 blueutil …).

Exit codes:
0 Success
1 General failure
64 Wrong usage like missing or unexpected arguments, wrong parameters
69 Bluetooth or interface not available
70 Internal error
71 System error like shortage of memory
75 Timeout error

내 트랙패드의 MAC Address 확인하기

$ bluetuil --connected

트랙패드가 연결된 상태에서 위 명령어를 실행합니다. 연결된 블루투스 장비들 이름이 나오는데,

address: XX-XX-XX-XX-XX-XX 의 형태로 출력되고, 세부 정보가 옆에 출력될 것입니다.

지금 필요한 정보는, address에 해당 되는 정보입니다. 저 문구를 복사합니다.

shell script 작성

#!/bin/zsh

export BLUEUTIL=`which blueutil`
export DEVICE_ID=XX:XX:XX:XX:XX:XX

res=$($BLUEUTIL --is-connected $DEVICE_ID)

if [[ "$res" = '1' ]]
then
$BLUEUTIL --unpair $DEVICE_ID
exit 0
fi

$BLUEUTIL --unpair $DEVICE_ID
sleep 1
$BLUEUTIL --pair $DEVICE_ID
sleep 1
$BLUEUTIL --connect $DEVICE_ID

vi나 nano 등의 에디터를 사용하여 위와 같은 shell을 작성해 줍니다.

위의 bin/zsh 부분은 본인이 사용하는 SHELL로 바꿔주면 됩니다.  bin/bash 등도 동작할 것입니다.

DEVICE_ID 부분에 앞서 복사한 Mac Address 값을 복사해 넣습니다. 단, 앞서 복사할 때는 하이픈이었던 부분을 이제 콜론으로 변경해서 기록합니다.

해당 shell 파일에 실행 권한을 부여한 다음 테스트 해봅시다.

트랙패드 페어링 전환

  • Mac1: 페어링 된 상태에서 shell 실행하면, unpair 됩니다.
  • Mac2: 페어링 되지 않은 상태에서 shell을 실행하면, 다시 pair 됩니다.
  • 적어도 한 번은 페어링 된 맥에서 사용합니다.
  • Mac1에서 Unpair를 하고 나서, Mac2에서 pair를 해야 잘 됩니다.
  • 만약, 잘 동작하지 않는다면 트랙패드의 전원을 껐다 켠 후 다시 시도해 봅니다.
  • 최악의 경우, 라이트닝 케이블을 꽂아서 강제로 페어링 시켜줍니다. 

Leave a Reply