Edit: My initial question does not appear to have a solution. Instead I used an alternate method. Scroll down to see the alternate method.
I'm looking for a solution to mute my mic in Discord that I can then add to my touchbar via bettertouchtool.
BTT cannot send key combos to Discord for whatever reason. As far as I can tell I have two options.
Use applescript to activate the Discord window, send the key press, then hide the window. This works, but flashing the application up for a moment is annoying. Worse when it's on another desktop as it will flip desktops over and then back.
Use applescript to click the top menu
to click the Discord menu, and work down through the UI elements to click the Mute button.
I'm not experienced enough with applescript to make the second option work, but I think it could work. Using UI browser I was able to get the path to the UI element:
How can I make this work? Any help is greatly appreciated. Thanks
ALTERNATE SOLUTION
What I am wanting to do here does not appear to be possible, so I'm just muting my mic at the OS level instead of Discord, and then adding a toggle button to my touchbar with BetterTouchTool. This has the added benefit of working system wide. Here's video of it in action:In case anyone else was wanting to do this these are the steps I took:
1. Create a new Applescript with the following script:
property storedInputLevel : missing value
if input volume of (get volume settings) is 0 then
set volume input volume storedInputLevel
return 1
else
tell application "System Events"
set storedInputLevel to input volume of (get volume settings)
end tell
set volume input volume 0
return 2
end if
Save the script somewhere.
2. Open up Better Touch Tool and create a new Touch Bar widget and set the widget to Run Apple Script and Show Return Value
3. In the window that pops up after selecting Run Apple Script and Show Return Value
you'll want to erase the test line in the box and give your widget a name:
3.a Click the appearance and settings button
4. In the Appearance and Settings
window you'll want to configure the following settings:
You don't need to set an alternate background color, but it helps to see you're muted at a glance.
For the icons you can use these:
Make sure that you set the Alternate color and icon if result matches regex
setting to 2.
Click Save.
5. On the new widget you created click on the drop down for Predefined action
and choose Run Apple Script (async in background)
.
6. In the window that popped up you'll want to click on Select Apple Script File
and then Choose Apple Script file from Disk
and browse to the script file you created earlier. Click save and you're done.
That's it. Your widget should toggle your mic on and off and the change should be reflected in the icon on your touch bar.
activate application "Discord" tell application "System Events" key code 46 using {shift down, command down} -- shift-command-left end tell
. It switches to the application and sends the key press to mute my microphone, but doing activate pops up the application.