narner
narner

Reputation: 3221

MacOS Service from SwiftUI App Not Showing Up

I'm trying to create a Service with my macOS SwiftUI app. Here's where I create/register it in the AppDelegate:


class AppDelegate: NSObject, NSApplicationDelegate {
    var statusBarItem: StatusBarItem!

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        statusBarItem = StatusBarItem()
        NSApp.servicesProvider = self
        NSUpdateDynamicServices()
    }
    
    @objc func processService(_ pboard: NSPasteboard, userData: String?, error: AutoreleasingUnsafeMutablePointer<NSString?>) {
        guard let items = pboard.pasteboardItems, !items.isEmpty else { return }
        
        for item in items {
            if let string = item.string(forType: .string) {
                // Handle the string data, e.g., copy it into your app or process it.
            }
        }
    }

}

And here's my Plsit entry for it:

enter image description here

I can see my service when running /System/Library/CoreServices/pbs -dump_pboard, but, it does now show up when highlighting text in TextEdit or Safari.

EDIT:

I did make sure that the app gets moved to the applications folder; and updated the plist a bit:

class AppDelegate: NSObject, NSApplicationDelegate {
    var statusBarItem: StatusBarItem!
    
    func applicationWillFinishLaunching(_ notification: Notification) {
        AppMover.moveIfNecessary()
    }

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        statusBarItem = StatusBarItem()
        NSApp.servicesProvider = self
        NSUpdateDynamicServices()
    }
    
    @objc func processService(_ pboard: NSPasteboard, userData: String?, error: AutoreleasingUnsafeMutablePointer<NSString?>) {
        guard let items = pboard.pasteboardItems, !items.isEmpty else { return }
        
        for item in items {
            if let string = item.string(forType: NSPasteboard.PasteboardType(rawValue: "public.utf8-plain-text")) {
                // Handle the string data, e.g., copy it into your app or process it.
            }
        }
    }
}

But still no effect

enter image description here

Upvotes: 1

Views: 176

Answers (0)

Related Questions