Get and Set Star Rating for Files (Not iTunes)


I am trying to read and write the star rating for files with KM and was surprised that it's not part of the file attributes action, because for me Tags & Ratings belong together :slight_smile:

I am trying to do it through the command line now, but also hit a roadblock. I can read them with

xattr -px testfile.txt | xxd -r -p | plutil -p -

but I have no idea how to write them, because xattr returns a bplist and needs one to set a new value. Obviously, the list is decoded with the code above, but I have no idea how to create a new one in order to set a new value.

  1. Does anybody know how to do this and can supply a quick snippet?
  2. Would this be a feature worthwhile implementing as an additional dropdown option for the "Get / Set File Attribute" macros?

Thank you,

I'm not aware of a star rating system in Finder; which app are you setting that in?

Star Rating is one of the common metadata attribute keys, but you are right, Finder doesn't expose it. I could swear that it used to be part of the "more info" window in older MacOS versions, but I might be wrong.

It works across multiple applications. The ones I use the most are PathFinder and Leap, which is a Tag Browser. Spotlight also picks them up,

Here are two things I found that might be helpful, in case you hadn't already seen them:

Hey, thank you.

Unfortunately, I don't speak python :frowning: But I saw the second link and gave it a try, but it doesn't work that way anymore. Even though you can pass a number to kMDItemStarRating and it even gets stored, the other apps don't pick it up.

A legit value looks like this now:

jhein:~ jhein$ xattr -pl untitled.txt bplist00#@
jhein:~ jhein$ xattr -plx untitled.txt
00000000  62 70 6C 69 73 74 30 30 23 40 08 00 00 00 00 00  |bplist00#@......|
00000010  00 08 00 00 00 00 00 00 01 01 00 00 00 00 00 00  |................|
00000020  00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000030  00 11                                            |..|
jhein:~ jhein$ 

And apparently you can decode the binary like this:

jhein:~ jhein$ xattr -px untitled.txt | xxd -r -p | plutil -p -
jhein:~ jhein$ 

My problem is that I don't know how to reverse that process in order to set a value.

1 Like

Yupp, that is very helpful. Thank you!

I've just tried with the Leap trial, and

xattr -w "" 3 ./Catch\ JS\ Error.png for me:

That's on macOS 10.14. What are you running?

1 Like

Ventura 13.3.1 (a) and I tried again just to be sure and it doesn't work unfortunately :frowning:

Correction: It does work in Leap, but only there. It doesn't work systemwide and other apps don't pick it up. Pathfinder and Hazel don't

It may be that different apps are using different metadata fields for the star ratings. Find/create a file that shows with 3 stars in all your different apps, then list the xattrs for that file to find what's been set.

Have a look at this Eclectic Light post for more about xattrs and some utilities that might help.

1 Like