T
T
Toly2016-10-01 21:35:45
Cocoa
Toly, 2016-10-01 21:35:45

How to get the comments of a file from NSURL?

On macOS, you can write a comment for each file. For example in GetInfo.
1543763564e44a9293f7c96bc24a5637.png
With method:

NSDate *date = nil;
[url getResourceValue:&date forKey:NSURLCreationDateKey error:nil];

I can get the date and time the file was created, as well as other additional information. But I did not find how to get a comment using this method. I also considered the possibility of getting file comments using the following methods NSFileManager:
[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize];

but here, too, without success.
Please tell me how can I get the file comment. Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Alexander Semchenko, 2016-10-01
@absterno

NSMetadataItem *originalFileMetadata = [[NSMetadataItem alloc] initWithURL:[NSURL URLWithString:@"file/path"]];
NSString * comment = [originalFileMetadata valueForAttribute:@"kMDItemFinderComment"];
NSLog(@"%@ ", comment);

That's how to get a comment if that.
s / s / it is worth rummaging here.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Headers/MDItem.h

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question