On macOS, the open command can launch applications like Brave Browser. I currently bind this to a hotkey in Karabiner-Elements to focus on Brave (or activate it if it's already running).
I've set up similar rules for Emacs as well:
{
"description": "left_command + e -> Emacs",
"manipulators": [
{
"from": {
"key_code": "e",
"modifiers": {
"mandatory": [
"left_command"
]
}
},
"to": [
{
"shell_command": "open -a emacs"
}
],
"type": "basic"
}
]
}
This is great for window management, but I'd like to do the same thing with the Terminal application itself. How can I focus on the Terminal app from within Karabiner-Elements? What is the shell command to open Terminal from the Terminal?
Following a Stack Overflow suggestion, I tried this approach, but it didn't work as expected:
{
"description": "left_command + k -> focus on terminal",
"manipulators": [
{
"from": {
"key_code": "b",
"modifiers": {
"mandatory": [
"left_command"
]
}
},
"to": [
{
"shell_command": "osascript -e 'tell application \"Terminal\" to activate' \
-e 'tell app \"System Events\" to keystroke \"n\" using command down'"
}
],
"type": "basic"
}
]
}
Source: Apple Stack Exchange Archive (CC BY-SA 4.0)