I checked the template provided in Xcode to create the FinderSync extension. Everything works well, except for two things:
a) The requestBadgeIdentifierForURL method is never called by the system when checking the folder so that the icons are not set. What's going on here? I am right in believing that this method should be called when I, for example. move or scroll controlled folder in Finder? By the way, the startObservingDirectoryAtURL and endObservingDirectoryAtURL methods are invoked properly in this context.
#import "FinderSync.h"
@interface FinderSync ()
@property NSURL *myFolderURL;
@end
@implementation FinderSync
- (instancetype)init {
self = [super init];
NSLog(@"%s launched from %@ ; compiled at %s", __PRETTY_FUNCTION__, [[NSBundle mainBundle] bundlePath], __TIME__);
self.myFolderURL = [NSURL fileURLWithPath:@"/Users/hmaass/Downloads"];
[FIFinderSyncController defaultController].directoryURLs = [NSSet setWithObject:self.myFolderURL];
[[FIFinderSyncController defaultController] setBadgeImage:[NSImage imageNamed: NSImageNameColorPanel] label:@"Status One" forBadgeIdentifier:@"One"];
[[FIFinderSyncController defaultController] setBadgeImage:[NSImage imageNamed: NSImageNameCaution] label:@"Status Two" forBadgeIdentifier:@"Two"];
return self;
}
#pragma mark - Primary Finder Sync protocol methods
- (void)beginObservingDirectoryAtURL:(NSURL *)url {
NSLog(@"beginObservingDirectoryAtURL:%@", url.filePathURL);
}
- (void)endObservingDirectoryAtURL:(NSURL *)url {
NSLog(@"endObservingDirectoryAtURL:%@", url.filePathURL);
}
- (void)requestBadgeIdentifierForURL:(NSURL *)url {
NSLog(@"requestBadgeIdentifierForURL:%@", url.filePathURL);
NSInteger whichBadge = [url.filePathURL hash] % 3;
NSString* badgeIdentifier = @[@"", @"One", @"Two"][whichBadge];
[[FIFinderSyncController defaultController] setBadgeIdentifier:badgeIdentifier forURL:url];
}
#pragma mark - Menu and toolbar item support
- (NSString *)toolbarItemName {
return @"testfifi";
}
- (NSString *)toolbarItemToolTip {
return @"testfifi: Click the toolbar item for a menu.";
}
- (NSImage *)toolbarItemImage {
return [NSImage imageNamed:NSImageNameCaution];
}
- (NSMenu *)menuForMenuKind:(FIMenuKind)whichMenu {
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
[menu addItemWithTitle:@"Example Menu Item" action:@selector(sampleAction:) keyEquivalent:@""];
return menu;
}
- (IBAction)sampleAction:(id)sender {
NSURL* target = [[FIFinderSyncController defaultController] targetedURL];
NSArray* items = [[FIFinderSyncController defaultController] selectedItemURLs];
NSLog(@"sampleAction: menu item: %@, target = %@, items = ", [sender title], [target filePathURL]);
[items enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@" %@", [obj filePathURL]);
}];
}
@end
b) I get the following message in the Xcode log console when starting the template above:
2015-08-25 15: 33: 00.300 testfifi [855: 8134] (colorGridView) (NSApplication) (NSColorPickerGridView): setter instance 2015-08-25 15: 33: 00.300 testfifi [855: 8134] () (NSApplication) (NSColorPickerGridView): 2015-08-25 15: 33: 00.321 testfifi [855: 8134] - [FinderSync init] /Users/hmaass/Library/Developer/Xcode/DerivedData/testtest -egudnxkifjxirpbrjkohnatmjuro/Build/Products/Debug/testtest.app/Contents/PlugIns/testfifi.appex; 20:38:18
- ?
!