Open the Finder Contextual Menu Via the Keyboard

I'm so sorry if this has been asked before. Maybe I'm not using the right terminology.

Is there a way to have a keyboard shortcut that pulls up the contextual menu of whatever file is selected in the front-most Finder window?

Nov-24-2021 23-16-23

In this gif I'm using the keyboard to scroll/navigate.
And using the mouse (not visible in the gif) to pull up the menu.
How do I skip from having to use navigate my mouse on a item that is already selected?

PCs have(/had?) an actual dedicated key for it on their keyboards.

Hey David,

This should be an utter no-brainer, but as usual Apple falls short when it comes to providing for users' convenience.

I've played with keybindings, and they're quite powerful if a bit obscure. I've never mapped the contextual menu though, so you're on your own there.

OS X Text System Keybindings

Text System Defaults and Key Bindings

You can also use a Keyboard Maestro found-image action to find the highlighted file using the highlight color. See this:

Drag Finder selection to "Found Image" in Chrome Browser window - #11 by ccstone

-Chris

1 Like

Chris, thanks so much.
This is a juicy one.
I'm gonna dive in. I'll report back :slight_smile:

1 Like

@ccstone phew
I very much appreciate the variety of links and solid content. It's probably way over my head for the little time I have. Though I was tempted to head into the world of keybindings. Fascinating stuff. Reminds me of the fun days of tech. But this is just one of the battles i have with the Finder and OS overall and I just don't have that sort of time anymore. And its prob way over my head anyway.

But who knows maybe this post inspires a new convo about it in here and for a whizz to get to the bottom of it!
This person from one of the things you linked seems to have made something? not sure, don't want to have to download something.

Yes, for the Finder anyway, using AppleScript. And for all other Apps using Keyboard Maestro's Move to Found Image Action to move and right-click at the highlighted item.

First the AppleScript approach (this AppleScript is from @eurobubba in this past post: Has Anyone Figured Out a Way to Replicate the Windows "Menu Key" on a Mac Using KM? - #8 by eurobubba)

.NOTE - this only works in the Finder (but as that was your need, maybe this will do it for you).

Once this Macro has opened the context menu of the selected file, you can select the menu item you want by either having Keyboard Maestro type the first letters of its name or by having Keyboard Maestro simulate arrow keys to move to the item you want.

Finder - Open Context Menu.kmmacros (4.5 KB)

on run
  try
    main()
  on error msg number errno
    if errno is not -128 then
      activate
      display alert msg message "Error Number : " & errno
    end if
  end try
end run

on main()
  --activate application "Finder"
  tell application "System Events"
    tell application process "Finder"
      set frontmost to true
      set ui to value of attribute "AXFocusedUIElement"
      tell application "Finder" to activate
      set a_class to class of ui
      if a_class is outline then
        tell ui
          try
            perform action "AXShowMenu"
            return
          on error
            beep
          end try
        end tell
        return
      else if a_class is scroll area then
        tell outline 1 of ui
          set a_row to item 1 of (rows where it is selected)
          tell UI element 1 of a_row
            try
              perform action "AXShowMenu"
            on error
              beep
            end try
          end tell
        end tell
      else if a_class is group then
        tell ui
          set an_item to item 1 of (UI elements where it is selected)
          tell an_item
            try
              perform action "AXShowMenu"
            on error
              beep
            end try
          end tell
        end tell
      else if a_class is browser then
        tell scroll area 1 of ui
          set n_list to count scroll areas
          repeat with n from n_list to 1 by -1
            tell list 1 of scroll area n
              set selected_elements to (UI elements whose selected is true)
              if length of selected_elements > 0 then
                tell item 1 of selected_elements
                  try
                    perform action "AXShowMenu"
                  on error
                    beep
                  end try
                end tell
                exit repeat
              end if
            end tell
          end repeat
        end tell
      end if
    end tell
  end tell
  
  -- return theResult
  
end main


on showMenu(anElement)
  
  tell me
    activate
    display dialog "WTF?"
  end tell
end showMenu

To invoke the Context Manu in other Apps I made another Macro here: (Has Anyone Figured Out a Way to Replicate the Windows "Menu Key" on a Mac Using KM? - #35 by Zabobon).

I agree. I can't believe Apple haven't assigned a key that just does this. It is one of the few things that Windows (the name that shall not be spoken...) has but the Mac doesn't :grinning:

2 Likes

hey @Zabobon thanks so much!

Trying the finder/applescript one first: I'm getting this error when i call your finder macro: "System Events got an error: Can’t get splitter group 1 of window "Documents" of application process "Finder". Invalid index."

I've dug into your AS but can't see anything I wand to tinker with.
Maybe you have an idea?
I've tried calling it on various windows and also the desktop, giving the same error.

p.s. what does the ui class represent? I'm seeing the outline / scroll area / group / browser variables

Thanks again!

Update: tried your other 'Click at Found Image' which works pretty well. Wish it didn't rely on the highlight colour. Gets confused sometimes. But it's SOMEthing. I have it assigned to ^+space

The AppleScript is just pasted into the Keyboard Maestro Action as was. It's a script that has been around for a while now. All I can say is it works fine for me (which is not much help but suggests the problem is not with the script...). Here it is working just now (in my case I highlight the file in Finder and press the shortcut that runs the Keyboard Maestro macro):

Screen Recording 2021-11-25 at 22.46.05-Animated GIF Small

It can usually work pretty well - but like I said it's a shame Apple don't just allow us to set a key to do this.

Agh – I think I've seen that before and forgotten...

In any case – on my system it's too slow to be realistically useful – 3+ seconds to run.

The appended macro gets the time down to about 0.5 seconds on my old MacBook Air running Mojave. (The System Events code may need adjusting for later versions of macOS.)

This will only work in the Finder of course.

-Chris


Finder ⇢ Contextual Menu on Selected Items.kmmacros (7.0 KB)
Keyboard Maestro Export

1 Like

Actually, you can get macOS to do this for you. But there's a price. You have to enable Voice Control in System Preferences, and then simply say "Right Click". Obviously that's not what the user wants here. But I'm trying to figure out a way to trick macOS using this technique. For example, there's an option in System Preferences called "Type to Siri", but oddly enough if you type the string "Right Click" to Siri, even with Voice Control enabled, it doesn't know what to do.

I was hoping that "Voice Control" could combine with "Type to Siri" so that you would end up with "Type to Control," but alas, that combination isn't working. Unless someone else can figure out how to splice these things together. I'll bet I could do it with Rogue Amoeba's Audio Hijack software which could feed the words "Right Click" into macOS's Voice Control. This way I could use macOS's voice synthesis to send the words "Right Click" into macOS which would result in a reliable right click interface. I'll bet you that will work.

1 Like

Great! I was hoping you would come up with a more efficient AppleScript!

You are going to so love getting your new Mac! :grinning:

As you've probably seen already, @ccstone has come up with another more efficient AppleScript (a couple of posts above). - hope that works for you. (I've tested for myself and it works great.)

1 Like

I do that with Better touch tool.
There is also an Alfred workflow to do that.
but nothing simple in KM.
Personaly I use the BTT shortcut in KM :wink:

1 Like

There's an updated version of the AppleScript to open the Finder contextual menu that been tested and works on Catalina and Ventura. You can find it here: