Is it possible to create a system wide AppleScript to access the Services Menu?

I often select text (+/- images) → right click → Services → click on one of the services menu items (usually a DevonThink or Scrivener menu item)

It’s possible to do so with keyboard maestro, but it requires me to write a different macro for each app and each services menu item. There is a way to write a system wide macro with keyboard maestro (write “APPLICATION” (in caps) instead of the app name, but it is unreliable.

Is it conceivable to write an AppleScript to do so ?

thanks in advance for your time and help

the following system wide keyboard maestro action is unreliable

I didn’t do any testing on this but I think something like this as a starting point will get you to Services, assuming the first menu is the Apple menu () and the second is the named app menu (Safari, Finder, etc):

tell application "System Events"
	set frontApp to (first process whose frontmost is true)
	tell frontApp
		click menu 1 of menu bar item 2 of menu bar 1
		select menu item "Services" of menu 1 of menu bar item 2 of menu bar 1
	end tell
end tell

thank you for your time. Unfortunately, in quite a few apps, the app → services menu is different from the context menu services menu which is what I was looking for.

You might be able to use the ‘Shortcuts --> Services’ to set a shortcut in the macOS Keyboard settings, rather than using Keyboard Maestro?

I’ve just been trying to use this today and have had mixed success, but perhaps it might be worth a try.

1 Like

thank you very much for the suggestion @Kaitlin
Unfortunately, the shortcuts → services route work for those situations where keyboard maestro works fine (Scrivener, safari, etc), but does not when I need it (Scrivener Scratchpad, Chrome, etc)

This will right click and select the services menu at the current mouse position:

Depends on the services menu existing and the mouse being where you want it to be.

1 Like

thank you for the suggestion. This is what I was currently doing and was looking for a more elegant solution.
Your input is greatly appreciated

I access services almost exclusively via LaunchBar. You can send the selection to it by way of its “Instand Send” feature and access every applicable service by typing a part of its name or a custom set up abbreviation.

1 Like

thank you. I use Launchbar, but it works for text only. I often select text + image (like a graph, etc)

As I had mentioned, I am using this method. The drawback is that the cursor must be right over the selected. Text. The challenge is to precede the right click action with a move mouse to found image action ie move mouse over selected text. Unfortunately it does not work consistently. Sometimes yes, sometimes no.

If someone has any idea about how to move mouse to selected text, it would be greatly appreciated, because it could solve the problem.

thanks again for your post

This is what I do, too. I would observe that 0.5 seconds is a long time for a menu to appear. I would encourage people to crank it down. I usually start with 0.2 seconds and either double or halve from there - depending on reliability.

For formatted text with images this might work:

  1. Copy the selection to the clipboard
  2. Invoke LaunchBar’s Clipboard history (which recognizes formatted text)
  3. Send the most recent entry to the service you want.

thank you. Unfortunately, the outcome is not reliable. Never works with Chrome (text only), often with Safari but not always.

You’re right. I actually changed it to .1 and that wasn’t long enough, so I defaulted it back to .5 without testing the incremental steps.

You might want to try this AppleScript instead of scripting the right click. It is going to depend on the app and what what the focussed UI element is. I don’t have DevonThink installed.

tell application "System Events"
	set theApplication to first application process whose frontmost is true
	set theControl to value of attribute "AXFocusedUIElement" of theApplication
	tell theControl
		perform action "AXShowMenu"
		return
	end tell
end tell

I try to avoid using Found Image actions, but sometimes they are the only hope :neutral_face:

:open_mouth: Is the difference not always that the context menu services are a sub-set of the app menu services list?

I’m not a super heavy user of the services menus (my key ones I have keyboard shortcuts for), to date I can’t say that I’ve ever spotted anything on a content menu list that wasn’t also on the app menu list. A quick check of a few apps and services for text and image selections didn’t throw up anything for me. I’m just surprised at such a discrepancy from Apple is all :man_shrugging:t2:

On a 2015 15” MBP I find 0.2 works most of the time. And if it doesn’t I’ve got bigger problems. :slight_smile:

Thanks Martin. I tried that on a couple of my macros that have a delay and 0.2 seems to work where 0.1 does not. What will I do with all of the .3 seconds free time I’ll be getting!

1 Like