You can write a comment for each file in macOS. For example in Get Info.

enter image description here

Using the 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 have not found how to get a comment using this method. I also considered the possibility to get file comments using the NSFileManager methods:

 [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize]; 

but here, too, to no avail.

Please tell me how I can get the file comment. Thank you all in advance.

2 answers 2

The answer was found on another forum.

A comment from the file can be obtained like this:

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

    This is not a public API that needs to be done via AppleScript or AppleEvent.

    The thing is called Spotlight comment.