Skip to content

Instantly share code, notes, and snippets.

@JakeTrock
Created November 23, 2020 15:23
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeTrock/6158cb81117605d75603fa637e72fd66 to your computer and use it in GitHub Desktop.
Save JakeTrock/6158cb81117605d75603fa637e72fd66 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
#improvement of Weslley S Pereira's script by Jacob Trock
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
import os
v = "88_D0_39_6C_6E_AC"
def toggle(tog=[0]):
tog[0] = not tog[0]
if tog[0]:
os.system('pacmd set-card-profile bluez_card.' + v + ' headset_head_unit')
t_btn.config(text='Switch Mic Off')
else:
os.system('pacmd set-card-profile bluez_card.' + v + ' a2dp_sink')
t_btn.config(text='Switch Mic On')
root = tk.Tk()
root.title('Toggler')
e = tk.Entry(textvariable=v)
e.insert(0, v)
e.pack()
t_btn = tk.Button(text='Switch Mic On', width=15, command=toggle)
t_btn.pack(pady=5)
root.mainloop()
@tomas-herman
Copy link

tomas-herman commented Jan 28, 2021

Thank you, this works beautifully, just modified v = "88_D0_39_6C_6E_AC" to my version of bluez_card and it works like a charm.

@JakeTrock
Copy link
Author

glad you liked it!

@sagarr
Copy link

sagarr commented May 11, 2021

It giving me below error
Failed to set card profile to 'headset_head_unit'

@JakeTrock
Copy link
Author

this is because that profile does not exist on your headset. perhaps this is an error with your sound system or your headset. Id suggest you turn it off then on again and see if anything changes. If not, then if you're on linux, then you should take a look at pulseaudio and your current bluetooth configs

@pbackx
Copy link

pbackx commented Jul 27, 2021

Thanks, just for reference, use pacmd list-cards when the bluetooth headset is connected to find the value for v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment