Adding a macOS Service to an app

Is this possible? I see a Services area in Xcode but am not sure what to do with it and google searches seem to focus on a user creating a service with automator instead of how to add one to an app. Any clues are welcome.

As I understand it, it should be possible to make an AppleScript app that provides a service. Automator just makes it a heck a lot easier.

See the Services Implementation Guide: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/SysServices/introduction.html#//apple_ref/doc/uid/10000101-SW1. You’d have to create an AppleScript app — or possibly you could get by with a script bundle — and edit the info.plist file with the appropriate keys to set up a services menu item and indicate its handler. Then the app would have to be placed in ~/Library/Services for the system to distribute it. If you get the details right it should ‘just work,’ but I don’t have the time to play with it right now. I’ll experiment tomorrow and see what happens.

The trickiest part, I expect, is that data seems to be provided to services through NSPasteBoard, which I personally find annoying to work with. But with some slogging it ought to work out.