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?
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?
@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.
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.
.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.
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
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
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):
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.)
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.
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.)