---
url: 'https://simonerescio.it/en/2022/08/switcheroo-bluetooth-keyboard-and-mouse-across-macs-made-easy'
title: 'Switcheroo, bluetooth keyboard and mouse across Macs made easy'
author:
  name: Simone Rescio
  url: 'https://simonerescio.it/en/about-me/'
date: '2022-08-21T00:29:08+02:00'
modified: '2026-04-25T16:14:49+02:00'
type: post
summary: Switcheroo helps you quickly move Bluetooth keyboard and mouse control across multiple Macs with a simple Automator workflow.
categories:
  - WebTech
tags:
  - automator
  - bluetooth
  - productivity
  - shell
image: 'https://simonerescio.it/wp-content/uploads/2022/08/law-switcheroo.jpg'
published: true
---

# Switcheroo, bluetooth keyboard and mouse across Macs made easy

Companies providing a MacBook as work laptops do a great favor to themselves and the people receiving them for productivity, years of usage have made me really fond of Mac OS versus the amount of maintenance my Windows workstations used to demand, often turning it into a second job on its own.

Still even though being pricy objects it’s not a good idea to think of mixing up your work device with your personal stuff, on one hand business security of course as you might download or do stuff that might endanger the biz, on the other hand you cannot really expect privacy on a machine you do not own now, would you?

For such reason I, as many others, did resort after being delighted by the Mac experience to get a personal one for more private and mundane purposes, so to benefit of the zero maintenance and it-just-works™ life.

While working at home though, you may want to up the game a bit by plugging into a bigger desktop setting with external peripherals such as monitor, *mouse and keyboard*, now as I want as less clutter on my desk as possible I prefer to use bluetooth ones, and here’s where things with Mac start to be less “ideal”.

Each time you want to “switch” the Mac to which your mouse and keyboard are connected, you’ll have to summon the bluetooth settings windows, unpair manually both devices and and re-pair them on the other machine each time you pass from one laptop to the other, making this an 8 clicks operation.

Your browser does not support HTML5 video. [Open GIF fallback](https://simonerescio.it/wp-content/uploads/2026/04/ace-ventura-two-spears-giphy-pQnpc1wl9SNB37ZtoN.gif).

 

What if this was reduced to just ***two (2)*** clicks?

- [1. Introducing: Switcheroo](#introducing-switcheroo)
- [2. Notes on stalling and timeout](#notes-on-stalling-and-timeout)

## Introducing: Switcheroo

So first things first, the base of this script is to be credited to [Ophir Stern](https://apple.stackexchange.com/users/442165/ophir-stern) on [apple.stackexchange,](https://apple.stackexchange.com/a/432091) to which I’ve added a bit of logic and variables to check which directory the tool is available, as it can differ among machines even using the same install method, and because we want to use it on two devices, I’ve made it into a function to accept the device address as argument so its easier to setup, replacing automatically the address separators from – (dashes) to : (colons) as required by `blueutils`.

Install either via `brew` or other package manager the `blueutil`package on both Macs, then run `which blueutil` and paste the respective paths in the `homePath` and `workPath` variables.

Then run `blueutil --paired` on the computer to which the peripherals are currently connected to get their physical addresses, and replace the dashes (-) with colons (:) then paste them in `keyboardAddress` and `mouseAddress`replacing the placeholders,

```
# paste the path to blueutil on both MacBook
homePath=/path/on/personal/mac/blueutil
workPath=/path/work/mac/blueutil

# past devices addresses
mouseIcon=🖱
mouseAddress=00-00-00-00-00-00
keyboardIcon=⌨️
keyboardAddress=11-11-11-11-11-11

# nothing to modify from here on
[ $(ls -A "$homePath" | wc -l) -ne 0 ] && blt=$homePath || blt=$workPath

switcheroo(){
	deviceAddress=$1
	deviceIcon=$2
	# blueutil wants the address with : instead of -, replace them
    deviceAddressBt=$(echo "$deviceAddress" | tr - :)
	successMessage="✅ connected to $deviceIcon"
	errorMessage="❌ couldn't connect to $deviceIcon"
	isDeviceConnected=$($blt --is-connected $deviceAddressBt)

    if [[ "$isDeviceConnected" = '1' ]]
    then
		sleep 1
    	$blt --unpair $deviceAddressBt; echo "disconnected $deviceIcon"
    else
		$blt --unpair $deviceAddressBt; sleep 1
		$blt --pair $deviceAddressBt; sleep 1
    	$blt --connect $deviceAddressBt --wait-connect $deviceAddressBt 5
		[ $? -eq 0 ] && echo $successMessage || echo $errorMessage
    fi
}

pid=$!
 { sleep 15; kill $pid; } &
switcheroo $mouseAddress $mouseIcon
switcheroo $keyboardAddress $keyboardIcon
```

Now launch Automator and select to create a new Application, then among actions search for “*shell*” and add the “*Execute shell script*” action, paste the amended script (or copy/paste first and amend in the IDE).

You’ve most likely noticed the presence of various emojis in the code, being a shell script we wouldn’t have any feedback while it’s running, to be aware that it has been launched and most importantly ended correctly or not we can use notifications, so insert two of them before and after the script block, then most importantly add between the script and the last notification the step “*Set variable value*” that will pass to the last notification the result of the `echo` commands.

Now you can hit `Cmd+S` to save and create the Application, and name it ***Switcheroo***.

[![Automator workflow used to configure Switcheroo](https://simonerescio.it/wp-content/uploads/2022/08/automator-switcheroo-steps-setup-1024x592.png)](https://simonerescio.it/wp-content/uploads/2022/08/automator-switcheroo-steps-setup.png)

[![Switcheroo app icon](https://simonerescio.it/wp-content/uploads/2022/08/Switcheroo-150x150.png)](https://simonerescio.it/wp-content/uploads/2022/08/Switcheroo.png)The freshly created application has the Automator icon though, to make it more recognizable you can single click to select it, hit `Cmd+i` then drag on the small icon on top left of the info window the following icon to override it.

| [![Drag the icon into the info panel](https://simonerescio.it/wp-content/uploads/2022/08/drag-icon-into-info-panel-266x300.jpg)](https://simonerescio.it/wp-content/uploads/2022/08/drag-icon-into-info-panel.jpg) | [![Updated Switcheroo icon](https://simonerescio.it/wp-content/uploads/2022/08/icon-updated-260x300.jpg)](https://simonerescio.it/wp-content/uploads/2022/08/icon-updated.jpg) |
| --- | --- |

Now move the application into a directory like your Dropbox or iCloud docs dir, then drag the application to the Dock bar, finally send a copy of the ***Switcheroo ***application to the other Mac as well and add it to the Dock bar there too.

Finally, on the Mac where the mouse and keyboard are currently connected, you can one click the ***Switcheroo*** icon in your Dock to have both devices instantly unpaired, and one second after you can click again the ***Switcheroo*** icon on the other Mac Dock to have both connected on the other laptop.

From 8 clicks to 2. 😎

## Notes on stalling and timeout

Unfortunately the bluetooth API may be unstable from time to time and some hiccups may happen in case the device does not happen to be on discovery mode or is not turned on at all, the command `blueutil --pair` in particular may hang indefinitely when the device is not found as it has not internal timeout nor a way to specify one.

There would be the handy `timeout` tool part of the `coreutils` library available via brew, however when used in conjunction with the command `blueutil --pair` , it results in the Mac asking a prompt confirm for the device to be connected which would kill the purpose of having fewer click.

Using the `timeout` command against bash functions within Automator proved next to impossibile, so in order to avoid not receiving any feedback when the script blocks, it will self terminate within 15 seconds.

 [](https://mastodon.social/share?text=http%3A%2F%2Fsresc.io%2F1fpN&title=Switcheroo%2C%20bluetooth%20keyboard%20and%20mouse%20across%20Macs%20made%20easy)[](https://www.linkedin.com/sharing/share-offsite/?url=http%3A%2F%2Fsresc.io%2F1fpN)[](https://simonerescio.it/en/2022/08/switcheroo-bluetooth-keyboard-and-mouse-across-macs-made-easy)[](https://reddit.com/submit?url=http%3A%2F%2Fsresc.io%2F1fpN&title=Switcheroo%2C%20bluetooth%20keyboard%20and%20mouse%20across%20Macs%20made%20easy)[](https://api.whatsapp.com/send?text=Switcheroo%2C%20bluetooth%20keyboard%20and%20mouse%20across%20Macs%20made%20easy http%3A%2F%2Fsresc.io%2F1fpN)[](https://bsky.app/intent/compose?text=Switcheroo%2C%20bluetooth%20keyboard%20and%20mouse%20across%20Macs%20made%20easy%20http%3A%2F%2Fsresc.io%2F1fpN)[](https://telegram.me/share/url?url=http%3A%2F%2Fsresc.io%2F1fpN&text=Switcheroo%2C%20bluetooth%20keyboard%20and%20mouse%20across%20Macs%20made%20easy)[](https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fsresc.io%2F1fpN)

