I ended up using Karabiner as suggested by CJK, with the following custom script which I placed under ~/.config/karabiner/assets/complex_modifications/custom.json
. Just replace AppName
with the name of your app and the "from"
keybind to your preferred combination. The format is described here.
{
"title": "Custom modifications",
"rules": [
{
"description": "Toggle AppName visibility",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "f1",
"modifiers": {
"mandatory": ["shift", "control", "option", "command"]
}
},
"to": [
{
"shell_command": "osascript -e 'tell application \"System Events\" to set visible of process \"AppName\" to true'"
}
],
"to_after_key_up": [
{
"shell_command": "osascript -e 'tell application \"System Events\" to set visible of process \"AppName\" to false'"
}
]
}
]
}
]
}
Then, inside of Karabiner-Elements, in the "Complex Modifications" tab, click on the "Add rule" button, then enable your custom rule (in my case, the application I want to toggle is Helium).
