Skip to content

Instantly share code, notes, and snippets.

@dreamorosi
Last active October 5, 2021 13:35
Show Gist options
  • Save dreamorosi/6c2d10fa7045e5b5713904ca7716e9ce to your computer and use it in GitHub Desktop.
Save dreamorosi/6c2d10fa7045e5b5713904ca7716e9ce to your computer and use it in GitHub Desktop.
Karabiner Elements script that works with OneKey Mute Button Edition from TechKeys and brings Chime foremost to mute/unmute or mutes Teams when foremost

This script works with Karabiner Elements and OneKey Mute Button Edition.

When the button is pressed it performs one of these actions evaluated in this order:

  • If MS Teams is the frontmost application then it toggles mute.
  • If Chime is the frontmost application then it toggles mute.
  • Else it brings Chime to the front and toggles mute.
{
"title": "Support USB Mute key for Amazon Chime on macOS",
"maintainers": ["dreamorosi"],
"homepage": "https://gist.github.com/dreamorosi/6c2d10fa7045e5b5713904ca7716e9ce",
"import_url": "karabiner://karabiner/assets/complex_modifications/import?url=https://gist.github.com/dreamorosi/6c2d10fa7045e5b5713904ca7716e9ce/raw/chimemute.json",
"rules": [
{
"description": "Remap USB mute key when MS Teams is frontmost",
"manipulators": [
{
"conditions": [
{
"identifiers": [
{
"product_id": 8447,
"vendor_id": 1003
}
],
"type": "device_if"
},
{
"bundle_identifiers": [
"^com\\.microsoft\\.teams"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "y",
"modifiers": {
"mandatory": [
"left_command"
]
}
},
"to": [
{
"key_code": "m",
"modifiers": [
"left_command",
"left_shift"
]
}
],
"type": "basic"
}
]
},
{
"description": "Remap USB mute key when Chime is frontmost",
"manipulators": [
{
"conditions": [
{
"identifiers": [
{
"product_id": 8447,
"vendor_id": 1003
}
],
"type": "device_if"
},
{
"bundle_identifiers": [
"^com\\.amazon\\.Amazon-Chime"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "y",
"modifiers": {
"mandatory": [
"left_command"
]
}
},
"to": [
{
"key_code": "y",
"modifiers": [
"left_command"
]
}
],
"type": "basic"
}
]
},
{
"description": "Remap USB mute key when Chime is not frontmost",
"manipulators": [
{
"conditions": [
{
"identifiers": [
{
"product_id": 8447,
"vendor_id": 1003
}
],
"type": "device_if"
},
{
"bundle_identifiers": [
"^com\\.amazon\\.Amazon-Chime"
],
"type": "frontmost_application_unless"
}
],
"from": {
"key_code": "y",
"modifiers": {
"mandatory": [
"left_command"
]
}
},
"to": [
{
"shell_command": "/usr/bin/osascript ~/.config/karabiner/chimeMuteToggle.scpt"
}
],
"type": "basic"
}
]
}
]
}
-- ~/.config/karabiner/chimeMuteToggle.scpt
on run params
set frontApp to (path to frontmost application as text)
set appl to "Amazon Chime"
set keyy to "y"
set modifier to command down
if frontApp is not equal to appl then
tell application appl
reopen
activate
end tell
repeat until application appl is running
delay 0.1
end repeat
-- IF YOU ARE GETTING INCONSISTENT (UN)MUTE BEHAVIOR, TRY INCREASING THE VALUE
-- BELOW FROM 0.1 TO 0.5 OR EVEN 1.0
delay 0.1
end if
tell application "System Events" to keystroke keyy using modifier
if frontApp is not equal to appl then
tell application frontApp
reopen
activate
end tell
end if
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment