How do desktop stacks detect screenshots?

Desktop stacks are able to detect screenshots separately from images, I was simply wondering how it does that.

Screenshot of desktop with two stacks, images and screenshots

It can't just be by filename because renaming a file to the exact format of the screenshot name does nothing to change the category. Is it some sort of embedded metadata in the screenshots themselves?


Solution 1:

Yes, it is done through the metadata saved with the file in the file system.

If you have a screenshot taken with Grab saved in X.png, you can run a command like this to show its extended attributes:

xattr -l X.png

You'll see that it has (among other things) the extended attribute "com.apple.metadata:kMDItemIsScreenCapture".

To learn more about these extended attributes that hold metadata, you can run:

mdls X.png

And you'll see there information related to the screenshot, such as for example:

kMDItemComment                         = "Screenshot"
kMDItemIsScreenCapture                 = 1
kMDItemScreenCaptureType               = "selection"
kMDItemScreenCaptureGlobalRect         = (
    2126,
    268,
    552,
    742
)