9

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 FinderSync Extension (like DemoFinderSync) look at the blue popup in the below image, in that case Extension is added in the System Preference with Check mark and called that principal class "FinderSync.m" as well.

Screen shot 1

  1. When i run application using my Application Scheme (like DemoApp) look at the blue popup in the below image, in that case Extension is added in the System Preference but without check mark and that principal class "FinderSync.m" do not call and FinderSync Extension does not work in this case.

Screen Shot 2

Does anybody have an idea how to enable Finder Extension in the System Preference using second scenario?

pkamb
  • 33,281
  • 23
  • 160
  • 191
jigs
  • 839
  • 1
  • 6
  • 23

3 Answers3

8

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
dbainbridge
  • 1,190
  • 11
  • 18
  • Its add in the system preference but do not enable as check mark as shown in second screen shot of my above posted question. – jigs Jul 07 '15 at 07:38
  • Look at man page for pluginkit and test via the command line to get it working. – dbainbridge Jul 07 '15 at 14:49
  • @dbainbridge system("pluginkit -e use -i com.domain.my-finder-extension"); script is not working in OSX Mojave, Have you faced this issue? Can you please provide solution for that? – jigs Dec 26 '18 at 11:52
  • can you help me? https://stackoverflow.com/questions/61770116/finder-overlays-extension-not-launching – Anoop Vaidya May 13 '20 at 14:40
6

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.

jigs
  • 839
  • 1
  • 6
  • 23
  • Hi, I am facing a similar issue in my app. The application is signed by a trusted certificate but when the app is launched for the first time on a mac, the extension is not auto enabled. Any leads ? – Sandeep T D S Jun 12 '17 at 16:11
  • Related questions: https://stackoverflow.com/questions/44117848/adding-product-module-name-to-nsextensionprincipalclass-in-findersync-plist-cras https://stackoverflow.com/questions/44017346/how-to-launch-finder-sync-extension-on-launching-the-main-app – Sandeep T D S Jun 12 '17 at 16:15
0

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:
pkamb
  • 33,281
  • 23
  • 160
  • 191
  • Also asking about the sandbox: https://stackoverflow.com/questions/50171851/how-to-launch-apps-finder-sync-extension-from-code – pkamb Sep 19 '18 at 22:49