Function to get macos tags of a file

Does anyone know of a function to find the macos tags of a file or directory? I tried the crate macos-tags, but the function read_tags from that crate doesn't seem to include user-defined tags, and it also loses the order of the tags which is important (red-orange is different from orange-red).

You can probably inspire yourself from the function you were using but without going through a HashSet and querying the user-defined tags too.

Hey, author of the library here and curious about your use-case.

  1. Why is the order important?
  2. It should read custom tags. What is the output for your file running this command?
xattr -px com.apple.metadata:_kMDItemUserTags yourfile | xxd -r -p | plutil -convert json -o - -

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.