Skip to content

Commit 6fd9c62

Browse files
Merge pull request #1003 from blastik/feat/magic-keyboard-switcher
adding magic keyboard switcher script
2 parents 0c54816 + 38a7a07 commit 6fd9c62

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# magic-keyboard-switcher
2+
Script command to easility switch the bluetooth connectivity of a single Magic Keyboard between several computers.
3+
4+
## How to setup
5+
6+
1. Install [blueutil](https://github.com/toy/blueutil). You can use [brew](https://brew.sh/) - `brew install blueutil`
7+
2. Find out your Magic Keyboard bluetooth MAC address. With the keyboard connected, keep the Option key pressed while you click on your status bar bluetooth icon.
8+
<div align="center">
9+
<img src="images/bluetooth menu.png" alt="Bluetooth menu" width="75%">
10+
</div>
11+
12+
3. Open the script file, set your Magic Keyboard bluetooth MAC address in the `BTMAC` variable and review the blueutil binary location set in the `BIN` variable.
13+
4. Remove `.template` from the file name.
14+
5. Say Ok when prompted about giving Bluetooth permissions to Raycast after executing the script command.
15+
16+
## How to switch the Magic Keyboard between computers
17+
18+
It's desirable to have Raycast and this script command installed in both computers.
19+
20+
First, run the script command in the one that has the keyboard currently connected. It will disconnect it and make it discoverable.
21+
Second, run the script command in the other computer. It should connect it.
168 KB
Loading
209 KB
Loading
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# Dependency: This script requires `blueutil` cli installed: https://github.com/toy/blueutil
4+
# Install via homebrew: `brew install blueutil`
5+
6+
# Required parameters:
7+
# @raycast.schemaVersion 1
8+
# @raycast.title Magic Keyboard switcher
9+
# @raycast.mode silent
10+
11+
# Optional parameters:
12+
# @raycast.icon images/logo.png
13+
# @raycast.packageName System
14+
15+
# Documentation:
16+
# @raycast.author blastik
17+
# @raycast.authorURL https://github.com/blastik
18+
# @raycast.description Switch a single magic keyboard between computers
19+
20+
# blueutil location
21+
BIN=/opt/homebrew/bin/blueutil
22+
23+
# Your Magic Keyboard MAC Address
24+
BTMAC='XX:XX:XX:XX:XX:XX'
25+
26+
CMD_VAL="$($BIN --is-connected $BTMAC)"
27+
CMD_UNPAIR="$BIN --unpair $BTMAC"
28+
CMD_PAIR="$BIN --pair $BTMAC"
29+
CMD_CONN="$BIN --connect $BTMAC"
30+
31+
if ! command -v blueutil &> /dev/null; then
32+
echo "blueutil command is required (https://github.com/toy/blueutil).";
33+
exit 1;
34+
fi
35+
36+
if [[ "$CMD_VAL" -eq 1 ]]; then
37+
echo "Connected to $BTMAC"
38+
echo "Going to disconnect $BTMAC"
39+
$($CMD_UNPAIR)
40+
if [[ $? -eq 0 ]]; then
41+
echo "Disconnected from $BTMAC"
42+
else
43+
echo "Failed to disconnect from $BTMAC"
44+
exit 1
45+
fi
46+
else
47+
echo "Not connected to $BTMAC"
48+
$($CMD_PAIR)
49+
sleep 1
50+
$($CMD_CONN)
51+
if [[ $? -eq 0 ]]; then
52+
echo "Connected to $BTMAC"
53+
else
54+
echo "Failed to connect to $BTMAC"
55+
exit 1
56+
fi
57+
fi

0 commit comments

Comments
 (0)