2014-07-03 27 views
3

我想以編程方式在文件和目錄中添加註釋。如何以編程方式在文件和/或目錄中添加註釋?

enter image description here

是否有可能呢?如果是,請幫助我實現這一點。我尋找從Cocoa框架直接API但沒有成功,我會很樂意以任何方式(可可,shell或任何腳本)做到這一點。

+0

看起來你不能用AppleScript來做它,因爲Finder的評論項被讀取LY。 –

+0

@ElTomato:我只對蘋果腳本做過同樣的事情。檢查我的答案 –

回答

4

我實現這由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); 
} 
+0

任何想法在這個http://stackoverflow.com/questions/24848678/add-nsscrollview-to-nsview-is-not-working? –

相關問題