Hi @halloleo, for the Finder context menu I use this AppleScript:
I found this:
Since I use a German macOS, you would have to change the word "teilen" to "share" or the corresponding word of your macOS.
This also applies to the term of action (messages by Message etc.)
tell application "Finder"
set sel to get the selection
if (sel is {}) then
log "Nothing selected! Can't proceed"
return
end if
set parentPath to (container of item 1 of sel) as alias
set desktopPath to (path to desktop folder)
if desktopPath is equal to parentPath then reveal sel
end tell
tell application "System Events"
tell process "Finder"
set teilenButton to (first button whose description is "Teilen") of toolbar 1 of window 1
ignoring application responses
click teilenButton
delay 0.1
end ignoring
end tell
end tell
do shell script "killall System\\ Events"
tell application "System Events"
click (menu item "Nachrichten") of menu 1 of teilenButton
end tell
But it can be done a little easier and more efficiently. If you use the BetterTouchTool app, you can set up access to actions in the context menu with this:
This works wonderfully in any app. You can also integrate this BetterTouchTool action into your KM macro via an AppleScript.
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
@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
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.
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:
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.
Here's an example @halloleo & @Zabobon of how I do it with BetterTouchTool:
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.
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" 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:
@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.