-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathSpotlightImporters.m
executable file
·103 lines (79 loc) · 2.65 KB
/
SpotlightImporters.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// SpotlightImporters.m
// KnockKnock
//
#import "File.h"
#import "Utilities.h"
#import "SpotlightImporters.h"
//plugin name
#define PLUGIN_NAME @"Spotlight Importers"
//plugin description
#define PLUGIN_DESCRIPTION NSLocalizedString(@"bundles loaded by Spotlight (mdworker)", @"bundles loaded by Spotlight (mdworker)")
//plugin icon
#define PLUGIN_ICON @"spotlightIcon"
//plugin search directories
NSString * const SPOTLIGHT_SEARCH_DIRECTORIES[] = {@"/System/Library/Spotlight", @"/Library/Spotlight", @"~/Library/Spotlight"};
@implementation SpotlightImporters
//init
// ->set name, description, etc
-(id)init
{
//super
self = [super init];
if(self)
{
//set name
self.name = PLUGIN_NAME;
//set description
self.description = PLUGIN_DESCRIPTION;
//set icon
self.icon = PLUGIN_ICON;
}
return self;
}
//scan for spotlight importers
-(void)scan
{
//all spotlight importers
NSArray* allImporters = nil;
//path to importer
NSString* importerPath = nil;
//File obj
File* fileObj = nil;
//dbg msg
//NSLog(@"%@: scanning", PLUGIN_NAME);
//iterate over all spotlight importer search directories
// get all spotlight importer bundles and process each of them
for(NSString* importerDirectory in expandPaths(SPOTLIGHT_SEARCH_DIRECTORIES, sizeof(SPOTLIGHT_SEARCH_DIRECTORIES)/sizeof(SPOTLIGHT_SEARCH_DIRECTORIES[0])))
{
//get all items in current directory
allImporters = directoryContents(importerDirectory, nil);
//iterate over all importers
// ->perform some sanity checks and then save
for(NSString* importer in allImporters)
{
//build full path to importer
importerPath = [NSString stringWithFormat:@"%@/%@", importerDirectory, importer];
//make sure importer is a bundle
// ->i.e. not just a random directory
if(YES != [[NSWorkspace sharedWorkspace] isFilePackageAtPath:importerPath])
{
//skip
continue;
}
//create File object for importer
fileObj = [[File alloc] initWithParams:@{KEY_RESULT_PLUGIN:self, KEY_RESULT_PATH:importerPath}];
//skip File objects that err'd out for any reason
if(nil == fileObj)
{
//skip
continue;
}
//process item
// ->save and report to UI
[super processItem:fileObj];
}
}//spotlight importer directories
return;
}
@end