Open Context Menu at selected item in macOS Finder using keyboard only with Karabiner

740 views Asked by At

While navigating macOS Finder with my keyboard, I want to be able to pull up the context menu for a file. This typically done by performing a right click of the mouse. This means that my searches for how to produce the context menu using only the keyboard lead me to macOS's Mouse Keys feature. This in turn requires the pointer to be located at the file in question.

I do not want to have to move the mouse with the keyboard. I would like to bypass the mouse and right clicking entirely and go straight to pulling up the context menu for a file via the keyboard.

Is this doable with Karabiner? If so, how? If not, by what other means may I achieve this?

1

There are 1 answers

0
clemsam lang On

[ Although the script below illustrates what Karabiner plus AppleScript are capable of there is an Apple-given, very mighty feature in: System Preferences > Keyboard > Keyboard > "Focus on …" that lets you choose –among others– Focus on Menu Bar (or similar, in English).
By activating this, next clicking on a preset (end-of-line-) shortcut you can input any new shortcut you like. ]

If you have selected (moved to) the file you want to virtually-right-click you might do it this way:

{  "description": "If in Finder click 'Ablage' …",
   "manipulators": [{
            "type": "basic",
            "from": {
                "key_code": "c",
                            "modifiers": { "mandatory": [
                                           "left_control", "left_shift" ] }
                    },
                      "to": [ { "shell_command": "osascript -e 'tell application \"System Events\" to click menu bar item \"Ablage\" of menu bar 1 of application process \"Finder\"'"
                            } ]
                    }]
}

This script will NOT open a context menu but Finder's "File" menu which holds identical information! Of course you can change my shortcut (Ctrl-Shift-C) to any one you prefer.

It assumes (= requires) that Finder is frontmost. (You'll have to replace "Ablage" by its English –or other– equivalent: "File" ?.)
It uses AppleScript commands triggered by an osascript shell-command.

(You'll get a shell-command thus: Record a task with Automator => Copy its "icons" to ScriptEditor => Copy relevant "tell application …" wording into an osascript like above.)