How to enable FinderSync Extension in macOS System Preferences

前端 未结 3 578
一向
一向 2020-12-09 12:59

I am integrating FinderSync Extension in my Cocoa Application to show badges in files and folders. Look at the below two scenario:

  1. When i run application using
相关标签:
3条回答
  • 2020-12-09 13:08

    Linking an answer I found on the Apple developer forum:

    https://forums.developer.apple.com/thread/77682

    When your App is outside the Sandbox, you can use:

    Objective-C:

    system("pluginkit -e use -i <yourFinderExtensionBundleID>");
    

    Swift:

    let pipe = Pipe()
    let task = Process()
    task.launchPath = "/usr/bin/pluginkit"
    task.arguments = ["-e", "use", "-i", "<yourFinderExtensionBundleID>"]
    task.standardOutput = pipe
    let file = pipe.fileHandleForReading
    task.launch()
    let result = NSString(data: file.readDataToEndOfFile(), encoding:
    
    0 讨论(0)
  • 2020-12-09 13:24

    Non-debug scheme (#if !DEBUG):

    system("pluginkit -e use -i com.domain.my-finder-extension");
    

    When running under debugger give path to your extension directly:

    NSString *pluginPath = [[[NSBundle mainBundle] builtInPlugInsPath] stringByAppendingPathComponent:@"My Finder Extension.appex"];
    NSString *pluginkitString = [NSString stringWithFormat:@"pluginkit -e use -a \"%@\"", pluginPath];
    system([pluginkitString cStringUsingEncoding:NSUTF8StringEncoding]);
    

    Specify this in your applicationDidFinishLaunching method. You should also manually turn this on only once so that if user turned your extension off in the System Preferences you don't turn it on every time your application starts. I set an NSUserDefaults key the first time user launches my app that has the finder sync extension support.

    0 讨论(0)
  • 2020-12-09 13:24

    I got the solution:

    Code to Enable Extension (bundle ID)

    system("pluginkit -e use -i YourAppBundleID")
    

    Code to Disable Extension (bundle ID)

    system("pluginkit -e ignore -i YourAppBundleID")
    

    Before i used:

    system("pluginkit -e use -i AppBundleID.FinderSync")
    

    so just remove ".FinderSync" its working.

    0 讨论(0)
提交回复
热议问题