Skip to main content
Inspiring
July 7, 2016
Answered

Event when image is rated or flagged

  • July 7, 2016
  • 1 reply
  • 557 views

is there an event handler, and also is there a way to rate images via script?

Situation at hand: same image exists in parallel folder structures, e.g. one for AI and the other one for PNG and JPG - I want a rating that the user applies to one of them to be automatically applied to the other one

This topic has been closed for replies.
Correct answer SuperMerlin

No there is no event.

Yes labels and ratings can be done via script in several ways.

Here is just one example.

N.B. Bridge only!

var file = File("/d/folder/another folder/etc/filename.jpg");

if(file.exists){

new Thumbnail(file).rating=3;

new Thumbnail(file).label="select";

}else{

    alert("oh dear this file does not exist!");

    }

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
July 7, 2016

No there is no event.

Yes labels and ratings can be done via script in several ways.

Here is just one example.

N.B. Bridge only!

var file = File("/d/folder/another folder/etc/filename.jpg");

if(file.exists){

new Thumbnail(file).rating=3;

new Thumbnail(file).label="select";

}else{

    alert("oh dear this file does not exist!");

    }

Inspiring
July 7, 2016

Hi,

too bad there is no easy way. I think I should consider checking whether a parallel folder exists (and has been visited - I assume it would not have children if it has not been visited), and then copy labels and ratings from the other folder. Unfortunately this seems be be one of those "long-running" operations.

Thanks for pointing out the easy access to the label and rating setting - I was about to read all about metadata...

Regards

Wolfgang

SuperMerlin
Inspiring
July 7, 2016

It can be done using metadata, also using Photoshop without opening the files.

You could have the script check the files in one folder then process the others with results from the first.

Another example using metadata:-

var f = File("/c/folder/folder2/filename.jpg");

setRatingLabel(f,5,"Select");

function setRatingLabel( file,Rating,Label){

if(!File(file).exists) return;

if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

        var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );

        var xmp = xmpf.getXMP();

        if(Rating != undefined){

        xmp.deleteProperty(XMPConst.NS_XMP, "Rating");

        xmp.setProperty(XMPConst.NS_XMP, "Rating", Rating);

        }

        if(Label != undefined){

        xmp.deleteProperty(XMPConst.NS_XMP, "Label");

        xmp.setProperty(XMPConst.NS_XMP, "Label", Label);

        }

      if (xmpf.canPutXMP( xmp )) {

         xmpf.putXMP( xmp );

      }

      xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );

};