mariuskiessling / alfred-airpods-connector

Quickly connect your AirPods :headphones: using this Alfred workflow!
MIT License
132 stars 11 forks source link

Connection Problem #9

Open ruttiratta opened 3 years ago

ruttiratta commented 3 years ago

I installed everything as the description says, but somehow, when I run the workflow to configure it, it won't find my AirPods. Help would be very much appreciated.

BenoitFroment commented 3 years ago

@ruttiratta Do u use an Apple M1 chip? Since I switched I have the same issue

ruttiratta commented 3 years ago

@BenoitFroment Yes, I do. Then maybe that is the problem 🤔

mariuskiessling commented 3 years ago

Hello all, sorry for only getting back to you now. Can you please enable debugging mode, try to add your AirPods again and paste the (redacted) output log from the bottom window here? I unfortunately do not have access to M1 hardware, yet.

image

erdnaavlis commented 3 years ago

I have the same issue in an M1.

Here's the output of the debugging:

[22:01:03.880] Logging Started...
[22:01:17.397] AirPods Connector[Keyword] Processing complete
[22:01:17.403] AirPods Connector[Keyword] Passing output '' to Arg and Vars
[22:01:17.404] AirPods Connector[Arg and Vars] Processing complete
[22:01:17.404] AirPods Connector[Arg and Vars] Passing output 'Please select your AirPods...' to Script Filter
[22:01:17.429] AirPods Connector[Script Filter] Queuing argument 'Please select your AirPods...'
[22:01:17.546] AirPods Connector[Script Filter] Script with argv 'Please select your AirPods...' finished
[22:01:17.547] AirPods Connector[Script Filter] {"items": []}

It's seems it's not getting any values. In case it's useful I also ran bluetoothconnector in the terminal and it seems to be working fine:

image

Any suggestions?

erdnaavlis commented 3 years ago

OK I had a bit more time to go through this. Basically the issue is that BluetoothConnector was in a different path (brew changed behavior). I've also changed it to use Python 3.x.

I had to change the beginning of the script get_devices.py to the following:

import subprocess
import re
import json

out = subprocess.run('/opt/homebrew/bin/BluetoothConnector', capture_output=True, text=True)
devicesRaw = out.stderr

deviceMacs = []
deviceNames = []
airPodsPosition = -1

And in the workflow I had to change the last stage ("Connect to provided bluetooth MAC") script to:

status=$1

if [ "$status" = "connected" ]
then
  /opt/homebrew/bin/BluetoothConnector --disconnect --notify $AIRPODS_MAC
else
  /opt/homebrew/bin/BluetoothConnector --connect --notify $AIRPODS_MAC
fi

Everything is working smoothly now! :)

mariuskiessling commented 3 years ago

Thank you very much for the change suggestion, @andrethrill. I will prepare a new version that is compatible with the new path of Homebrew binaries and the next few days!

griptoe commented 3 years ago

Hi, Just wondering if this has been updated yet. I am also using Apple M1, and it is not configuring.

griptoe commented 3 years ago

@andrethrill I have tried your fix but am getting this error, I have also updated python to the latest version

out = subprocess.run('/opt/homebrew/bin/BluetoothConnector', capture_output=True, text=True) AttributeError: 'module' object has no attribute 'run

Devin-Yeung commented 2 years ago

@andrethrill I have tried your fix but am getting this error, I have also updated python to the latest version

out = subprocess.run('/opt/homebrew/bin/BluetoothConnector', capture_output=True, text=True) AttributeError: 'module' object has no attribute 'run

I just ran into the same problem.My solution is to modify the beginning of the script get_devices.py to the following:

#!/usr/bin/env python3
AndreKucharzyk commented 2 years ago

Not working on MacBook M1

mikeoertli commented 2 years ago

I finally had a chance to dig into this a little bit - apologies in advance as I haven't really done much with Alfred workflows and not much more with python.

https://github.com/mikeoertli/alfred-airpods-connector/releases/tag/v2.0

https://github.com/mikeoertli/alfred-airpods-connector

I ended up doing a bit of a facelift to the workflow and scripts (some necessary, some superficial, some just as part of my learning/exploration).

The main issues I encountered (that I can remember) were:

  1. python2 vs python3 - the workflow used at least 1 "run python script" which will run with whatever version of python is symlinked to /usr/bin/python (the script is defined in the workflow, not calling an external script). As part of this, each of the python scripts implements what @Devin-Yeung has suggested above.
  2. Homebrew has moved for Apple Silicon Macs (according to their installation documentation it is standard practice to use /opt/homebrew/ for ARM architecture vs. /usr/local/bin for Intel. I fixed all references to work for Apple Silicon and most of them to use HOMEBREW_PREFIX so would work on Apple Silicon OR Intel, but I don't think I caught them all so I suspect my changes/release as linked above will break Intel Macs.
  3. It appears that bluetooth connection status is reported differently for paired, but not connected, devices. This caused the prior regex to fail for me because it never shows Connected: No for me, the line with Connected is simply not there. I didn't bother to check if this is a difference related to number 4 in this list or not, but it might be.
  4. The call to os.popen4 no longer works, I didn't debug this, I just used the recommendation from @andrethrill above.

I don't intend to maintain a fork here and I'm not sure how complete my changes are, but I figured a fork with a release was the best option (rather than committing the alfredworkflow file) since several of the changes are in the alfredworkflow file itself.

I have tested this on 2 newer Macs w/ Python 3.9.x and 3.10.x and it seems to be working for me through a decent chunk of manual testing.

I will open a merge request when I get a chance and if there is anything I can do to help get this back into the mainline of development here, please don't hesitate to reach out @mariuskiessling. Thanks for such an awesome utility!

UPDATE: PR opened: https://github.com/mariuskiessling/alfred-airpods-connector/pull/11

igoooor commented 2 years ago

thanks @mikeoertli your version works perfectly on my mac m1 with python 3.9

orthand commented 1 year ago

Hey @mikeoertli, thanks for updating the workflow. In case you're still maintaining the fork: BluetoothConnector seems to have some problems with Ventura (https://github.com/lapfelix/BluetoothConnector/issues/20). Switching to blueutil, which is still actively maintained, fixed those problems for me on 13.2.1.

if [ "$status" = "connected" ]
then
    ${HOMEBREW_PREFIX:-/opt/homebrew}/bin/blueutil --disconnect $AIRPODS_MAC
else
    ${HOMEBREW_PREFIX:-/opt/homebrew}/bin/blueutil --connect $AIRPODS_MAC
fi
mikeoertli commented 1 year ago

Hey @mikeoertli, thanks for updating the workflow. In case you're still maintaining the fork: BluetoothConnector seems to have some problems with Ventura (lapfelix/BluetoothConnector#20). Switching to blueutil, which is still actively maintained, fixed those problems for me on 13.2.1.

if [ "$status" = "connected" ]
then
    ${HOMEBREW_PREFIX:-/opt/homebrew}/bin/blueutil --disconnect $AIRPODS_MAC
else
    ${HOMEBREW_PREFIX:-/opt/homebrew}/bin/blueutil --connect $AIRPODS_MAC
fi

Thanks for the info and for reaching out!

Unfortunately, I likely won't be maintaining it... I switched to Raycast a while back and haven't had much need to look back. I'll add a "todo" for at least updating the readme with that info and then likely archive the repo.