5

You can programmatically invoke services if you already know the name of the service. As best I understand, the Services menu is built by calling a validation method on each published Service.

Is there a way to access a list of installed Services without using the Services user dialog?

EDIT: I don't mean background processes. I am talking about the items in the Services menu in Finder. Overview of what they are here.

mooglinux
  • 815
  • 1
  • 11
  • 27

3 Answers3

1

The somewhat supported (but poorly documented) approach is to call lsregister and parse the output. The output does not have a documented or guaranteed format, however.

You run it this way for the commandline:

LSREGISTER="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
${LSREGISTER} -dump

(Yes, it's deeply buried and not in PATH.)

This dumps a ton of information. You just want services, which look like this:

--------------------------------------------------------------------------------
service id:                 FileMerge/Compare To Master (0x16f8)
menu:                       FileMerge/Compare To Master
port:                       FileMerge
message:                    diffVersusMasterService
timeout:                    -1
send types:                 "NSFilenamesPboardType"

The part you want is the "menu" tag:

$LSREGISTER -dump | grep ^menu: | cut -c 29-

Obviously you can parse this more directly in code, but the only way I know of that's even vaguely supported is to run lsregister.

OK, that's obnoxious. If you're willing to use private APIs, it's pretty straightforward. Define an interface for LSServiceRecord:

@interface LSServiceRecord
+ (id)enumerator;
- (NSString *)localizedMenuItemTitle;
@end

And then you can enumerate over them to get the menu titles:

id enumerator = [LSServiceRecord enumerator];

for (id item in enumerator) {
    NSLog(@"%@", [item localizedMenuItemTitle]);
}

You might find the portName property helpful. It's the name of the application that registered the service. You might also find +[LSServiceRecord enumeratorForContentsOfPasteboard:] useful if you're trying to limit it to valid services.

If you want to explore more, I recommend Hopper, and looking in LaunchServices framework.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
0

There is an API provided by Apple, documented here - https://developer.apple.com/documentation/coreservices/launch_services

Note that you need to have your service registered in system database and consuming code needs to know about its existence.

I hope this helps.

Amogh Sarpotdar
  • 544
  • 4
  • 15
  • https://stackoverflow.com/questions/41442474/how-to-register-service-from-app-in-macos-application may be more relevant to what you are trying to achieve. – Amogh Sarpotdar Apr 11 '22 at 13:32
-1

try launchctl list, see https://guide.macports.org/chunked/reference.startupitems.html for some more info,.

  • 1
    That isn't the type of service I am talking about. I am talking about services that allow you to use functions of other applications. Overview of use is [here.](http://www.macworld.com/article/1163996/software-utilities/how-to-use-services-in-mac-os-x.html) – mooglinux Jan 19 '17 at 00:23