• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Read metadata for a file without Photoshop or Bridge

Advocate ,
Jun 03, 2013 Jun 03, 2013

Copy link to clipboard

Copied

Hi

Suppose I have a file in desktop called "test.jpg". So I create this variable:

var myFile = new File ("~/Desktop/test.jpg");

This file has some keywords and instructions I need to read. And if the reading process finds the correct keyword, then it copies the file to the appropriated folder. Well, in resume, I could do everything directlly using #target estoolkit. I´d not like to involve (opening) Photoshop or Bridge.

Is it possible to read the metadata of a file without targetting Bridge or Photoshop? Reading the reference I did not find any method or property for this, expect for the metadata library. BUT

If I try to load the metadata library using:

if (ExternalObject.AdobeXMPScript == undefined) {

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

    };

then it sure will returns an error file or folder does not exists..

Any idea how I could proceed to load this library and read the metadata of a file directlly?

Thank you very much

Best Regards

Gustavo.

TOPICS
Actions and scripting

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Jun 04, 2013 Jun 04, 2013

The documentation on working with XMP is in the JavaScript Tools Guide.

var test = new File("~/Desktop/Test.jpg");

var xmpf = new XMPFile( test.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ );

var xmp = xmpf.getXMP();

xmpf.closeFile();

var modDate = xmp.getProperty(XMPConst.NS_XMP, "ModifyDate").toString();

alert(modDate);

Votes

Translate

Translate
Adobe
Valorous Hero ,
Jun 03, 2013 Jun 03, 2013

Copy link to clipboard

Copied

External libraries require you have Photoshop or Bridge as the target so no you can't do it direct in ExtendScript.

The only other way would be to use ExifTool and read/write the details to/from a file, then you could use ExtendScript only, but it would be much slower.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 03, 2013 Jun 03, 2013

Copy link to clipboard

Copied

I probably would not use ExtendScript to do this… I would avoid the file object's copy() method as it creates a new file…

The modified date gets bumped and can be a PITA… Using Abobe's ESTK only Bridge can move files to location without doing this…

You would probably be better served using something else your system supports… ExifTool is available in a few flavors…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 03, 2013 Jun 03, 2013

Copy link to clipboard

Copied

Exiftool supports reading/writing metadata as well as copying/moving files using the command line. I think whether you use it as part of an ESTK script or standalone bat/bash file would depend on if the keywords used changes often. I don't know if ExifTool changes the modified date when moving files based on metadata tags.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 04, 2013 Jun 04, 2013

Copy link to clipboard

Copied

Hi friends

Thank you very much for your inputs. Muppet....what do you mean when you write The modified date gets bumped and can be a PITA? What means "PITA"?

So, if it´s impossible to invoke [directly] the default library without targetting Bridge or Photoshop...I´ll simplify the things and use Bridge to house the script. No problem.

So, look at what I´m doing:

#target bridge

if (ExternalObject.AdobeXMPScript == undefined) {

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

};

var test = new File ("~/Desktop/Test.jpg");

var xmp = test.metadata;

alert(xmp);

...But, the alert in Adobe Bridge is returning nothing (""). And I know this image exists and it has metadata.

I remember to use metadata for reading the currently selected image in Content panel of Bridge (and it worked), but never tried direrctly declaring a file and reading this way.

Am I missing anything obvious?

Thank you very much

Gustavo.


Message was edited by: Gustavo Del Vechio

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 04, 2013 Jun 04, 2013

Copy link to clipboard

Copied

Gustavo… The Bridge app has a built-in method to move files about… This does in fact move the original to a new location…

The ESTK file object has NO move method… What you can do is copy the file to new location and remove the original…

But a NEW file is created and the data put into this… If like me you put these files in other documents…

Links in AI or ID then you will be constantly having to update all the modified links…

You may well be neadlessly backing it all up again too…

PITA == pain in the ar$e

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 05, 2013 Jun 05, 2013

Copy link to clipboard

Copied

Hi Muppet

Thank you very much. Yeah, as my original concept was creating a script targetting estoolkit, I created a function that copies the file, check if it was really copied and removes from origin. This portion of script is working preety well.

Thank you very much for the tips about this method and the direct moveTo() of Bridge.

The problem was really the metadata.

Michael, thank you very much. It worked. I´ll replace the calling of ModifyData with the appropriate to get keywords.

Just a question, for curiosity....

After the third line (var xmp = xmpf.getXMP()), I inserted an alert to know what returned. And the alert returned empty. Now, your own alert in the end of code returned correct because you added the method .toString() in the end of declaring modData variable.

Why was necessary to use this .toString() method??? Why my alert to know xmp returned empty??

Just really for curiosity. To learn a little

Best Regards

Gustavo.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 05, 2013 Jun 05, 2013

Copy link to clipboard

Copied

After the third line (var xmp = xmpf.getXMP()), I inserted an alert to know what returned. And the alert returned empty.

An alert after that line should have returned [object XMPMeta]. alert(xmp.serialize()); would display the full contents of the xmp.

The toString() in my code was not needed to return a xmp object. I just added that to make sure that it returned a string.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 06, 2013 Jun 06, 2013

Copy link to clipboard

Copied

Thank you Michael for the explanations

Best Regards

Gustavo.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 06, 2013 Jun 06, 2013

Copy link to clipboard

Copied

What strange. Perhaps I´m mssing anything, but I´m still not getting sucess on reading the metadata of files. See what I´m doing:

#target bridge

if (ExternalObject.AdobeXMPScript == undefined) {

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

};

var mainFolder = new Folder ("~/Desktop/MyFolder");

var mainFiles = mainFolder.getFiles();

for (var g=0;g<mainFiles.length;g++){

     if (mainFiles instanceof File){         

          var xmpf = new XMPFile(mainFiles.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);

          var xmp = xmpf.getXMP();

          alert(xmp); //it returns empty here??

          xmpf.closeFile();

          var historico = xmp.getProperty(XMPConst.NS_PHOTOSHOP, "History");          

          alert(historico); //it also returns empty here

          ...continue looking for keywords, labels and processing the commands of the script

     }

     else

     if (mainFiles instanceof Folder){

          findSubfolders (mainFiles); //this is a function to look for files in subfolders. It will be recursive. It´s working correctlly.

     };

};

What Am I missing?

Thank you very much

Gustavo.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 06, 2013 Jun 06, 2013

Copy link to clipboard

Copied

As I said you can use alert(xmp.serialize()); to see the entire XMP. If you just want to make sure that the var xmp contains a XMP object you could use alert(xmp.toString());

As far as the history alert goes, are you sure the files have that property in that namespace? PHOTOSHOP History is different than xmpMM history. So you should either check that the namespace and property exists or that the var xmp is not undefined before the alert. But even if property does exists and was returned to var xmp, that variable would hold an xmp object. So you sometimes need to do something like this.

if( historico != undefined ) alert(historico.value);

or

if( historico != undefined ) alert(historico.toString());

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

Thank you Michael

Perfect! About the History, what I want to read is really Photoshop history.

Just one more thing, if you could help.

I got sucess reading labels, history and document´s instructions. Great. But I´m not getting sucess of reading the keywords assigned to the document (the ones inserted in Adobe Bridge).

I already tried:

var keys = new String (xmp.getProperty(XMPConst.NS_DC, "Description"));

var keys = new Array (xmp.getProperty(XMPConst.NS_DC, "Description"));

var keys = new String (xmp.getProperty(XMPConst.NS_DC, "subject"));

var keys = new Array (xmp.getProperty(XMPConst.NS_DC, "subject"));

... and other tests...

But no sucess. If the variable "keys" could receive the keywords as array, better. But as string no problem too.

Do you know the correct syntax to read keywords and store in a variable??

Thank you very much

Gustavo.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

Again I think it would be helpful for you to read the XMP docs. I don't mind answering your questions but you might save some time not having to wait.

The values in the XMP are stored using different data types. Not all values can be retreved using a simple getProperty call. Here is one way to get the keywords as an array. Assumes you already have already gotten the xmp.

var res = [];

var count = xmp.countArrayItems(XMPConst.NS_DC, "subject");

for( var k=1; k<= count;k++ ){   

     res.push(xmp.getArrayItem(XMPConst.NS_DC, "subject", k).toString());

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

LATEST

Thank you Michael

I´ll try that.

Yes I´m reading the XMP chapter in the JavaScript Tools Guide, but I assume it´s still complicated to me. At true, these 2 subjects: xmp and sending messages to other softwares (Bridge Talk) are the subjects I think it´s the most complicated yet.

Thank you again

Gustavo.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 04, 2013 Jun 04, 2013

Copy link to clipboard

Copied

The documentation on working with XMP is in the JavaScript Tools Guide.

var test = new File("~/Desktop/Test.jpg");

var xmpf = new XMPFile( test.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ );

var xmp = xmpf.getXMP();

xmpf.closeFile();

var modDate = xmp.getProperty(XMPConst.NS_XMP, "ModifyDate").toString();

alert(modDate);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines