GithubHelp home page GithubHelp logo

lapfelix / bluetoothconnector Goto Github PK

View Code? Open in Web Editor NEW
526.0 10.0 35.0 116 KB

Simple macOS CLI to connect/disconnect a Bluetooth device. Useful for AirPods or other Bluetooth headphones.

License: MIT License

Swift 100.00%
bluetooth macos airpods beatsx swift swift-package swift-package-manager beats macos-cli automator-workflow shortcut

bluetoothconnector's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluetoothconnector's Issues

Build failure in MacOS Ventura

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?

Feature Request: --toggle command

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.

Turn off 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.

MAC addresses are case-sensitive

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.

Device listed as connected but "status" shows it "Not paired to device"

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.

Pairing ?

Do you have a plan to add this future
thanks for the great work

ctrl+c does not exit

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?

Doesn't connect if bluetooth is off

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.

error or warnning message

macos10.13 swift4

swift[56921:212676] Exception NSInvalidArgumentException thrown while decoding IOBluetoothSDPServiceRecord

Add option/key --notify-cli-only

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!

brew formula

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.

Permission denied

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

License

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 :)

--notify always reports "Connected" after ~20 secs

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.