It seems the screenshot @Hans-Peter_Henkel provided shows the script from this post. I played around with this script and it works in many apps, to a varying degree:
- Finder, Mail (not in side bar), Bear, Quiver, TaskPaper, EagleFiler, …
- In Text entry areas only: TextEdit, iA Writer, Safari, Things, Notes, Stickies, Keyboard Maestro, …
- Works not in Pages, Numbers, Excel, Word, BBEdit, …
Here the script as KM macro, only slightly modified:
[test] Invoke Contextual Menu on Focused Element.kmmacros (3.5 KB)
It can be for different reasons that it doesn’t work in all applications.
Most likely: The focused element does not support AXShowMenu
and you have to target a different element. But other reasons are possible, of course.
So, to make the script work with more apps, you’d have to work on a trial and error basis: Each time you encounter an app where it doesn’t work, try to find the appropriate way to generate the contextual menu and add it conditionally to your script.
For example, with the following modification the script will now also generate the contextual menu in KM when an action or a macro in the macro list is selected (not only when the cursor is inside a text area, as with the original script):
tell application "System Events"
set frontApp to name of first process whose frontmost is true
tell application process frontApp
try
set theSelection to value of attribute "AXFocusedUIElement"
tell theSelection
set defaultAction to perform action "AXShowMenu"
if defaultAction is missing value then
tell (first group whose selected is true) to perform action "AXShowMenu"
end if
end tell
on error errMsg number errNum
display alert errMsg & return & return & errNum
end try
end tell
end tell
[test] Invoke Contextual Menu on Focused Element (Extended).kmmacros (3.8 KB)
Contextual menu in KM, selection or cursor in text entry area:
Contextual menu in KM, action selected:
Contextual menu in KM, macro in macro list selected:
It still won’t work in Word, Numbers, etc. But you get the idea.