Skip to main content
Known Participant
February 19, 2025
Question

get and set rating with JavaScript

  • February 19, 2025
  • 1 reply
  • 225 views

I am trying to get and set the rating (stars) of JPEG and RAW data with JavaScript, but I cannot find an interface to do this.

I already get the file name and other information. Is there any techniques?

 

 

#target bridge

var selectedItems = app.document.selections;
var currentFolder = null;
if (selectedItems.length > 0) {
    currentFolder = selectedItems[0].parent.path;
} else {
    currentFolder = "~/Pictures";
}

var d = Folder.selectDialog("select folder", currentFolder);
var f = d.getFiles();

for(var i = 0; i < f.length; i++){
    alert(f[i].name, f[i].rating); // rating is undefined
}

 

 

1 reply

Legend
February 19, 2025

You can't use files, you need to use thumbnails. RAW files don't have a rating. That info is stored in the XMP sidecar which is a separate file.

thumbs = app.document.selections;
for(var i = 0; i < thumbs.length; i++){
   thumbs[i].rating = 1;
   }
Known Participant
February 19, 2025

Thanks. I misunderstood the implementation.

 

What I ultimately wanted to do was select two folders with the file dialog and copy the ratings in one folder to the other.
It is easy to do getFiles() from selectDialog(), but is it possible to access the thumbnails (or ratings) in a specific folder as well?

Legend
February 19, 2025

You would have to do matching of filenames, have you written that part?