Created
October 3, 2019 18:30
-
-
Save cyrus007/49b367669116bd1acdc75cab58545add to your computer and use it in GitHub Desktop.
Auto pair with BT speaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#file autorun | |
#!/bin/bash | |
bluetoothctl << EOF | |
connect [enter your MAC add] | |
EOF | |
---------------------------------------------------------------------------- | |
#file on.py | |
#!/usr/bin/python | |
# | |
# Monitor removal of bluetooth reciever | |
import os | |
import sys | |
import subprocess | |
import time | |
def blue_it(): | |
status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) | |
while status == 0: | |
print("Bluetooth UP") | |
print(status) | |
time.sleep(15) | |
status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) | |
else: | |
waiting() | |
def waiting(): | |
subprocess.call('killall -9 pulseaudio', shell=True) | |
time.sleep(3) | |
subprocess.call('pulseaudio --start', shell=True) | |
time.sleep(2) | |
status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) | |
while status == 2: | |
print("Bluetooth DOWN") | |
print(status) | |
subprocess.call('~/scripts/autopair', shell=True) | |
time.sleep(15) | |
status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) | |
else: | |
blue_it() | |
blue_it() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment