lapfelix / bluetoothconnector Goto Github PK
View Code? Open in Web Editor NEWSimple macOS CLI to connect/disconnect a Bluetooth device. Useful for AirPods or other Bluetooth headphones.
License: MIT License
Simple macOS CLI to connect/disconnect a Bluetooth device. Useful for AirPods or other Bluetooth headphones.
License: MIT License
It gets the devices that are paired or connected but cannot disconnect them.
blueutil
works fine and is not difficult to use.
Hello
Homebrew maintainer here.
The 2.0.0 version fails to build with the following error:
2023-03-20T20:52:36.6899400Z Creating working copy for https://github.com/apple/swift-argument-parser
2023-03-20T20:52:36.6900000Z Working copy of https://github.com/apple/swift-argument-parser resolved at 0.0.2
2023-03-20T20:52:36.6900990Z warning: 'swift-argument-parser': failed loading cached manifest for 'swift-argument-parser': Error Domain=NSCocoaErrorDomain Code=4 "The file “manifests” doesn’t exist." UserInfo={NSFilePath=/Users/brew/Library/Caches/org.swift.swiftpm/manifests, NSUnderlyingError=0x600002845aa0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2023-03-20T20:52:36.6902160Z warning: 'swift-argument-parser': failed storing manifest for 'swift-argument-parser' in cache: Error Domain=NSCocoaErrorDomain Code=4 "The file “manifests” doesn’t exist." UserInfo={NSFilePath=/Users/brew/Library/Caches/org.swift.swiftpm/manifests, NSUnderlyingError=0x60000284d800 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2023-03-20T20:52:36.6903780Z warning: 'swift-argument-parser': failed closing cache: Error Domain=NSCocoaErrorDomain Code=4 "The file “manifests” doesn’t exist." UserInfo={NSFilePath=/Users/brew/Library/Caches/org.swift.swiftpm/manifests, NSUnderlyingError=0x60000284c000 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2023-03-20T20:52:36.6905650Z warning: Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an optional Swift library package that can be downloaded from "More Downloads" for Apple Developers at https://developer.apple.com/download/more/
2023-03-20T20:52:36.6906280Z Building for production...
2023-03-20T20:52:36.6906810Z remark: Incremental compilation has been disabled: it is not compatible with whole module optimization[1/2] Compiling ArgumentParser Argument.swift
2023-03-20T20:52:36.6907440Z remark: Incremental compilation has been disabled: it is not compatible with whole module optimization[2/3] Compiling BluetoothConnector main.swift
2023-03-20T20:52:36.6908290Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:116:25: error: extra argument 'wrappedValue' in call
2023-03-20T20:52:36.6908800Z var connect: Bool = false
2023-03-20T20:52:36.6909140Z ^
2023-03-20T20:52:36.6909640Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:119:28: error: extra argument 'wrappedValue' in call
2023-03-20T20:52:36.6910620Z var disconnect: Bool = false
2023-03-20T20:52:36.6911020Z ^
2023-03-20T20:52:36.6911720Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:122:24: error: extra argument 'wrappedValue' in call
2023-03-20T20:52:36.6912220Z var status: Bool = false
2023-03-20T20:52:36.6912490Z ^
2023-03-20T20:52:36.6913570Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:125:24: error: extra argument 'wrappedValue' in call
2023-03-20T20:52:36.6914110Z var notify: Bool = false
2023-03-20T20:52:36.6914500Z ^
2023-03-20T20:52:36.6915350Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:114:8: error: type 'BluetoothConnector' does not conform to protocol 'Decodable'
2023-03-20T20:52:36.6915980Z struct BluetoothConnector: ParsableCommand {
2023-03-20T20:52:36.6916470Z ^
2023-03-20T20:52:36.6917040Z Swift.Decodable:2:5: note: protocol requires initializer 'init(from:)' with type 'Decodable'
2023-03-20T20:52:36.6917400Z init(from decoder: Decoder) throws
2023-03-20T20:52:36.6917800Z ^
2023-03-20T20:52:36.6918560Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:116:9: note: cannot automatically synthesize 'Decodable' because '<<error type>>' does not conform to 'Decodable'
2023-03-20T20:52:36.6919130Z var connect: Bool = false
2023-03-20T20:52:36.6919400Z ^
2023-03-20T20:52:36.6920040Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:119:9: note: cannot automatically synthesize 'Decodable' because '<<error type>>' does not conform to 'Decodable'
2023-03-20T20:52:36.6920650Z var disconnect: Bool = false
2023-03-20T20:52:36.6920930Z ^
2023-03-20T20:52:36.6922110Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:122:9: note: cannot automatically synthesize 'Decodable' because '<<error type>>' does not conform to 'Decodable'
2023-03-20T20:52:36.6923040Z var status: Bool = false
2023-03-20T20:52:36.6923610Z ^
2023-03-20T20:52:36.6925030Z /private/tmp/bluetoothconnector-20230320-4420-ok4dr/BluetoothConnector-2.0.0/Sources/BluetoothConnector/main.swift:125:9: note: cannot automatically synthesize 'Decodable' because '<<error type>>' does not conform to 'Decodable'
2023-03-20T20:52:36.6925950Z var notify: Bool = false
2023-03-20T20:52:36.6926500Z ^
There are some new commits on master since the last release. Could you tag a new release so that we try to rebuild bluetoothconnector
?
I think the title says it all: it would be nice to have a --toggle
option, so that a single alias or shortcut can be used to connect an unconnected device or disconnect a connected device.
Is it possible to turn off a device with this?
I would like to turn off my mouse when my mac goes to sleep.
I small movement of the mouse turns the mac on and i would like to prevent this.
For some reason, MAC addresses are case-sensitive. This caused some confusion until I realized it. I recommend covert all mac address inputs to lowercase. This supports copy/paste from outputs such as system_profiler SPBluetoothDataType
to obtain a device's address, which are uppercase.
not able to connect iPhone via bluetooth for MacOS Monterey
When I run BlueToothConnector without parameters it lists my keyboard as da-84-3e-56-b9-bf Connected 0 Ergonomic Keyboard
but when I try to get status or disconnect using commands like BluetoothConnector --status da-84-3e-56-b9-bf
I get the message Not paired to device
Since the list shows my device as connected I would expect to be able to control it. Any help you can provide would be appreciated.
More info: The keyboard is a Microsoft Surface Ergonomic keyboard. If I have not typed anything for ~5 minutes the keyboard sleeps and it takes a few keystrokes to wake it up. This is very frustrating as keys I have typed are missed and I have to start over. When using Windows there is an option to prevent the device from sleeping. Mac does not have that option and so I am trying to keep it awake by interacting with it at a device level.
Do you have a plan to add this future
thanks for the great work
Is is possible also shown RSSI info when Connected?
I've searched this a method related to this:
https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1431127-rssi
weird, i know. but it seems to be the case. whether passing the --disconnect
flag or not. adding --notify
fixes it, but, well, notification.
If I try to connect to a device which isn't available, obviously the connect will fail.
However, it can take awhile to fail. I would like to be exit to kill the process whilst I am waiting.
Usually ctrl+c does that, but it seems to do nothing in this case.
Perhaps BluetoothConnector
should respect ctrl+c?
Not sure if this was intended, but the BluetoothConnector
doesn't work/exits without error if the bluetooth is turned off. Readme.md
also fails to mention this requirement.
Ideally it should automatically turn on bluetooth if it is off and then attempt to connect to a bluetooth device.
macos10.13 swift4
swift[56921:212676] Exception NSInvalidArgumentException thrown while decoding IOBluetoothSDPServiceRecord
Thank you for very usefull app!
Is it possible to add new optional key like --notify-cli-only
?
I want to use Terminal Notifier for Notifications (because it can reuse last one and not pollute all Notification Center).
When I run it like this:
BluetoothConnector 00-00-00-00-00-00 --notify | terminal-notifier -title AirPods -group Bluetooth -ignoreDnD
I got two notifications same time (I don't want to disable notification for Script Editor).
Thank you!
Thank you ❤️ for this new 2.0 version! I'm using this very successfully in an Alfred4 workflow to quickly switch audio outputs.
Does the brew formula automatically get updated or does something need to be pushed? It's still providing the 1.3.0 version.
Whatever I try, I keep getting a permission denied error:
zsh:1: permission denied: /usr/local/bin/BluetoothConnector
Running the chmod command doesn't seem to work, even when running it sudo.
-FIXED: installation was not executed properly
Hi @lapfelix,
thanks for this handy wrapper to quickly connect / disconnect Bluetooth devices. I would like to use the compiled binary in a custom Alfred 3 workflow, which I want to open source on GitHub (ideally under MIT).
Do you mind adding a license to this repository so that me and others can be sure that we are allowed to use your BluetoothConnector?
Cheers :)
BluetoothConnector --notify $MAC
(with $MAC == my airpods) always reports "Successfully connected" after 20 secs.
This happens even while another terminal window runs BluetoothConnector --status $MAC
in a loop and always shows "Disconnected".
macOS 13.4.1 (c) , BluetoothConnector 2.0.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.