Open Context Menu at Point and Click a Menu Item in There

@Zabobon in 3 hours I'll be back at the Mac and then I'll give you an explanation and also a KM macro to it

1 Like

Thank you @appleianer. No hurry. It was cheeky of me to ask. Very grateful.

@Zabobon here is a short video on how to use the KM macro :point_down:

Here is the macro for it:

05)UUID AS <B85F 210209T131219>.kmmacros (24,1 KB) 05)UUID AS <B85F 210209T131219>

Would you also be interested in the workflow of inserting KM macro AppleScript into BTT and running KM macros via touch gesture.... has saved me a lot of shortcuts :wink:

3 Likes

Wonderful. Thank you @appleianer . I will have fun playing with this today!

Of course I would be interested :smiling_face:︎. But maybe it should be in a new thread as this is beginning to deviate from @halloleo's original question?

1 Like

Hi @appleianer! This sounds pretty impresive - not sure though if I want to add with BTT another tool in the mix...

So, KM has still no built-in solution?

1 Like

@halloleo unfortunately in KM there are limited possibilities to work with gesture control (mouse, trackpad).
I prefer to work in KM with macro groups in palette form. To not have to remember so many shortcuts, I work a lot with BetterTouchTool gestures.

Here's an example of how I create my screenshots and edit them in Snagit, all without a shortcut or other trigger from within KM.... so only touch gestures :wink:

Video :point_down:

BetterTouchToll is, for its capabilities, very affordable and is regularly developed by the developer.

Have a look at the documentation.

https://docs.folivora.ai

There are also many tutorials to find. You can test BTT for 45 days.

If you use a Setapp subscription, BTT would be included there as well.

@Zabobon I sent you a direct message.

Hi @halloleo - if you find an AppleScript that invokes the context menu of a specific App you can run that AppleScript from Keyboard Maestro.

Or you can use "right-click at Found Image" (which can work well - although I know you wanted solutions without that element).

Or, if you are prepared to move the mouse curser to the point where a contextual menu can be invoked, you can use Keyboard Maestro to right-click and then jump to the item you want by having Keyboard Maestro type its name and have Keyboard Maestro press "enter" to open the item.

But basically, no Keyboard Maestro can't simply access and run a contextual menu item. It would be great if it could.

1 Like

Hey @halloleo,

This is too vague.

The contextual menu on macOS is not a universally accessible thing with a devoted API provided by Apple.

Different applications may require different techniques.

And no – unfortunately there is no canon.

If you're more specific about what you want to do, we'll be better able to help.

-Chris

That's exactly what I need (and that's what I meant with "Open Context menu at point" in my initial description - sorry if this was not clear...) So I will try:

Thanks for this!

Thanks Chris. See this reply above for details.

1 Like

Hi @halloleo

Here is an example to get you started. It is for the Music App and replicates the context menu for a selected track. The mouse pointer needs to also be over the selected item for this to work.

If you wanted to adapt this to your own use, you would change the name of the Playlist to one of your own. But this example is really just to show the concept - the same basic approach would work in any Mac app.

One thing I have found - it can be useful to put very short pauses in to the Macro (as in the example) just to help the Mac OS catch up with the Macro.

Context Menu in Music App - Example for Forum.kmmacros (35.1 KB)

3 Likes

Here's an example @halloleo & @Zabobon of how I do it with BetterTouchTool:

2021_02_10_Support_1

Insert only the context actions into the BTT action and that's it. Now you can choose a shortcut, a touch gesture or insert the BTT action via an AppleScript into your KM macro.

@peternlewis that would be a very good feature for one of the next KM versions.

1 Like

Thanks @Zabobon. That's in principle what I now tried as well. It works and I'm happy enough with it.

However I am aware the method is very brittle or even dangerous: Biggest problem is that the macro does not know which menu item in the context menu finally is the highlighted one before the Simulated Keystroke return fires the menu item action off:

Say, you invoke your macro by accident on a mouse position where the context menu does not contain an entry "Add to Playlist" but an entry "Erase the harddisk" :wink: and somehow the highlight ends finally up on this entry, then Simulated Keystroke return might have devastating effect...

It would be great if we can read which menu item is the highlighted one, before teh macro presses return.

@appleianer What happens in BTT when you specify a context menu item which isn't there? Does then by accident can another be fired as with the above described KM method?

@halloleo in both the BTT example, and the KM example from @Zabobon, you should limit your workflow to the program in which it is to be executed.

In my BTT example I have entered the exact name of the context menu actions. If something is no longer present during execution (in my Gif = KM Forum,) then it looks like this:

2021_02_11_Support_1

@Zabobon has used the same method in his macro. KM needs the pauses between the actions to write the context action correctly. If you should consider this and the context menu action is no longer present, KM shows you an error message.

If you don’t include the last “Return” Action in the Macro (or disable it) the Macro will stop at that point with the item highlighted and you can choose to press Return yourself to select the currently highlighted item on the context menu (or not).

In fact, this is how I would suggest you set up these kind of Macros so you can test them to see that they are doing what you intend before simply firing them off - for the reasons you mention.

When building Macros I often put long pauses (3 seconds or more) after key points just so I can see everything is doing what I expect. Once I’m happy the Macro is robust I remove the pauses or make them much shorter.

With a Macro that goes more than one level into a Context Menu (as in the Music Macro included in my earlier post) I would first just build it to select the first item in the Context Menu (without firing that item with a Return Key Action). Then I would go on to get it to the item in the next level of the menu. And all the time with those long pauses.

Even with the finished Macro I might leave pauses just so I can be reassured it is doing what I want each time I fire it.

And as @appleianer has pointed out - if the item doesn’t exist the Macro would just end with an error. So, it’s not that dangerous.

Replying to myself.

@alexcr Started a Thread on a very similar question a few months ago.

I have to say that the main problem I have found with trying to automate context menus is that the mouse pointer has to be directly over the highlighted item before the Macro is Triggered.

This means the Macro cannot be Triggered from a Keyboard Maestro Menu as that involves moving the mouse away from the selected item.

With AppleScript it is possible to invoke the Context Menu of a highlighted item without the mouse hovering over it. But there is no generic AppleScript. It is a different Script for each Application. And it seems that apart from an AppleScript to do this in the Finder, no others are out there (from my searches in the past).

With @appleianer’s BetterTouchTool method I have found the same thing - i.e. it only works if the mouse is floating on top of the highlighted item. As soon as the mouse moves away (even though the item is still highlighted) it doesn’t work. (Unless I am doing it wrong @appleianer?)

1 Like

No @Zabobon you do nothing wrong. You can put this action first in your KM macro just to be safe.

2021-02-11_10-30-19

This would ensure that the cursor will be over the correct selection.

1 Like

You are absolutely right @appleianer - that works really well!

Just for completeness for @halloleo I'll point out that the highlight colour needs to be copy and pasted from the actual App on your computer as the highlight colour might not be blue. In my case Music has red as the highlight colour.

Also to add that I like to put a sound at the end of the Macro so I can hear it has done its job.

So, adding in @appleianer's suggestion for the start of the Macro and adding the Notification Sound at the end the Music Playlist example Macro would look like this:

Context Menu in Music App - Example for Forum [version 2].kmmacros (43.2 KB)

1 Like