我想以編程方式在文件和目錄中添加註釋。如何以編程方式在文件和/或目錄中添加註釋?
是否有可能呢?如果是,請幫助我實現這一點。我尋找從Cocoa框架直接API但沒有成功,我會很樂意以任何方式(可可,shell或任何腳本)做到這一點。
我想以編程方式在文件和目錄中添加註釋。如何以編程方式在文件和/或目錄中添加註釋?
是否有可能呢?如果是,請幫助我實現這一點。我尋找從Cocoa框架直接API但沒有成功,我會很樂意以任何方式(可可,shell或任何腳本)做到這一點。
我實現這由Apple腳本包裹在Objective-C中:
NSString *comment = @"hi boys";
NSOpenPanel *op = [NSOpenPanel new];
NSInteger answer = [op runModal];
if (answer == NSOKButton) {
NSURL *url = [op URL];
NSMutableString *appleScriptString = [NSMutableString new];
[appleScriptString appendString:@"TELL APPLICATION \"FINDER\"\n"];
NSString *setPath = [NSString stringWithFormat:@"SET filePath TO \"%@\" AS POSIX FILE \n", [url absoluteString]];
[appleScriptString appendString:setPath];
NSString *setComment = [NSString stringWithFormat:@"SET COMMENT OF (filePath AS ALIAS) TO \"%@\" \n", comment];
[appleScriptString appendString:setComment];
[appleScriptString appendString:@"END TELL"];
NSAppleScript *commentorScript = [[NSAppleScript alloc] initWithSource:appleScriptString];
NSDictionary *dictErr;
[commentorScript executeAndReturnError:&dictErr];
NSLog(@"Dict error = %@", dictErr);
}
任何想法在這個http://stackoverflow.com/questions/24848678/add-nsscrollview-to-nsview-is-not-working? –
AFAIK沒有公共API,如果谷歌的Spotlight註釋,你會看到這一切都是基於的AppleEvents,AppleScript的或XATTR各種解決方案..喜歡
http://www.cocoabuilder.com/archive/cocoa/178663-writing-spotlight-comments.html http://www.cocoabuilder.com/archive/cocoa/305493-adding-spotlight-comment-data-to-folder-file.html http://cocoadev.com/SpotlightAndTagging
我找到了答案,並感謝您的指導:) –
看起來你不能用AppleScript來做它,因爲Finder的評論項被讀取LY。 –
@ElTomato:我只對蘋果腳本做過同樣的事情。檢查我的答案 –