Implementing One-Click Bluetooth Device Connection with Alfred
I’m a strong supporter of wireless devices like AirPods and haven’t used wired mice or headphones for many years. However, there’s a common scenario in daily use: my AirPods are usually connected to my iPhone, but sometimes, like when I need to join a meeting, I need to quickly connect them to my Mac. The current process is: scroll mouse to the Bluetooth icon in the top-right corner of the screen => click the Bluetooth icon, select AirPods => select connect. OK, it’s cumbersome, so I wanted to create a workflow to quickly connect and disconnect Bluetooth devices.
Current Effect
When you select a disconnected device, the device will connect; conversely, it will disconnect. Mom no longer needs to perform cumbersome Bluetooth connection operations.
Download link: Click here
Usage Notes
- Pairing still needs to be done manually in the system Bluetooth panel; this only lists paired Bluetooth devices
- Select a Bluetooth device and press Enter to connect or disconnect the Bluetooth device
- Supports AirPods left and right earphone battery level display
Implementation Foundation
- Third-party library
blueutil
, the workflow itself just executes this command to display and connect devices. hammerspoon
reads system Bluetooth device battery information for AirPods battery display. If you don’t need battery information display, just don’t install it - I’ve implemented error handling.
Current Limitations
- To ensure timely display of Bluetooth device battery information, I had to rely on hammerspoon, since Alfred itself doesn’t have the capability to access system information and needs to rely on AppleScript, Shell, etc.
- Limited by Alfred’s Script Filter design, I must ensure getting the latest battery information before displaying devices. So I set up 2 keywords, requiring users to press Enter one more time - this is an unavoidable workaround.