Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch Finder Sync Extension on launching the main app?

In my Cocoa application, I have a finder sync extension.

On launching the application, my finder sync extension doesn't start automatically.

I need to go to System Preferences -> Extensions and enable it.

How do i make sure that on launch of my main application (.app) file the finder sync extension is launched and is enabled?

like image 695
Sandeep T D S Avatar asked Nov 07 '22 22:11

Sandeep T D S


1 Answers

Checkout https://blog.codecentric.de/en/2018/09/finder-sync-extension/

There is a section Restarting FinderSyncExtension on app launch with instructions on how to restart FinderSyncExtension on app launch and thus make it more reliable:

+ (void) restart
{
    NSString* bundleID = NSBundle.mainBundle.bundleIdentifier;
    NSString* extBundleID = [NSString stringWithFormat:@"%@.FinderSyncExt", bundleID];
    NSArray<NSRunningApplication*>* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:extBundleID];
    ASTEach(apps, ^(NSRunningApplication* app) {
        NSString* killCommand = [NSString stringWithFormat:@"kill -s 9 %d", app.processIdentifier];
        system(killCommand.UTF8String);
    });

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSString* runCommand = [NSString stringWithFormat:@"pluginkit -e use -i %@", extBundleID];
        system(runCommand.UTF8String);
    });
}
like image 144
mixtly87 Avatar answered Nov 15 '22 06:11

mixtly87