How to obtain a document identifier from a suffix on macOS?

Viewed 380

I am looking for a way to obtain a document identifier by it's extension/suffix by using either Python, Swift or Command-Line.

For example, having *.pxm as an input I am looking for com.pixelmator.pxm -> /Applications/Pixelmator Pro.ap. Does anyone have an idea?

I already found UTTypeCreatePreferredIdentifierForTag but the Carbon Framework is deprecated and therefore I can't use this.

1 Answers

The UTTypeCreatePreferredIdentifierForTag has deprecated since iOS14, so you need to use UTType in that case, but if your deployment target is below then you still need to use first one.

Here is simple demo:

import UniformTypeIdentifiers

...

    let type = UTType(filenameExtension: "pxm")
    print(type?.identifier ?? "unknown")

Related