gpt4 book ai didi

objective-c - 如何以编程方式在文件和/或目录中添加注释?

转载 作者:搜寻专家 更新时间:2023-10-30 20:02:33 25 4
gpt4 key购买 nike

我正在尝试以编程方式在文件和目录中添加注释。

enter image description here

可以吗?如果是,请帮助我实现这一目标。

我从 Cocoa 框架中寻找一个直接的 API 但没有成功,我很乐意通过任何方式(cocoa、shell 或任何脚本)来做到这一点。

最佳答案

我通过 Apple Script 包装在 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);
}

关于objective-c - 如何以编程方式在文件和/或目录中添加注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24548752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com