Script to get metadata without opening the file

Engaged ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

Hello everyone,

I'm using windows 10 and I have a file with a tag on its metadata:

AG_Ps_100_0-1619280394227.png

 

Here is how it looks on Photoshop:

AG_Ps_100_1-1619280903431.png

 

 

I know how to get the keywords of an open document:

var docKeywords = activeDocument.info.keywords.toString();

 

 

I'm trying to get the keywords without opening the file if that's possible (perhaps via Shell or something)

 

Any help will be greatly appreciated.

Thanks.

TOPICS
Actions and scripting, How to, Windows

Views

282

Likes

translate

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
Most Valuable Participant ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

You have to "open" the file somewhere, be that an Adobe app or a tool from an alternate vendor, so this doesn't really make much sense. Even on a command line you would need a tool like Imagemagikk. The super-sleek solution you seem to look for doesn't really exist, so you should focus on your efforts in XMP/ Bridge scripting or PS.

 

Mylenium

Likes

translate

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
Engaged ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

in VBA for example (Excel) I can create a shell object and check without opening nothing. The shell let's you get the data you need.

AG_Ps_100_0-1619284442737.png

 

 

 

I'm 99% sure this can be done as well in Photoshop.

Likes

translate

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
Adobe Community Professional ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

@Mylenium 

 

It surprised me when I learned that Photoshop could directly access the XMP metadata without actually opening the binary image data into Photoshop (similar to how Bridge and ExifTool work). So your suggestion to focus on XMP is a good suggestion. The post from jazz-y and here at PS-Scripts backs this up.

 

Bridge often makes more sense from a workflow point of view, however it is much tougher to script (at least for me) than Photoshop.

Likes

translate

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
Enthusiast ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

 

var f = 'e:/testFile.tif'
try {
    if (!ExternalObject.AdobeXMPScript)ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript')
        var xmpFile = new XMPFile(f, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ),
        xmp = xmpFile.getXMP();
    if (xmp.doesPropertyExist(XMPConst.NS_DC, 'subject')) {
        var i = xmp.iterator(XMPConst.ITERATOR_JUST_LEAFNODES, XMPConst.NS_DC, 'subject'),
            output = [];
        while (true) {
            var subject = i.next();
            if (subject) { output.push(subject.value) }
            else { break; }
        }
        alert(output)
    }
} catch (e) { }

 

Likes

translate

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
Adobe Community Professional ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

@jazz-y 

 

I can't get your script to alert?

 

I have verified the document path/name/metadata...

Likes

translate

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
Enthusiast ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

 

I forgot to warn that XMPFile does not use file objects, but string paths to files (in system format). Try this:
try {
    var f = File.openDialog('Open file');
    if (!ExternalObject.AdobeXMPScript)ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript')
        var xmpFile = new XMPFile(f.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ),
        xmp = xmpFile.getXMP();
    if (xmp.doesPropertyExist(XMPConst.NS_DC, 'subject')) {
        var i = xmp.iterator(XMPConst.ITERATOR_JUST_LEAFNODES, XMPConst.NS_DC, 'subject'),
            output = [];
        while (true) {
            var subject = i.next();
            if (subject) { output.push(subject.value) }
            else { break; }
        }
        alert(output)
    }
} catch (e) { }

 

Likes

translate

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
Adobe Community Professional ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

Thank you – that works as expected, cheers!

Likes

translate

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
Adobe Community Professional ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

It would be helpful to know what the next step is, when you have the keywords – then what? Do you need the keywords for use within a larger Photohsop script? Do you need to dump the keywords to a file such as a CSV or XML etc.

Likes

translate

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
Engaged ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

Part of a script, for example if has the keyword then doAction("TEST","Set 1");

 

I saw that xmp explanation elsewhere but know that I have a tif file, it has no xmp file.

 

Is it really the case that there is no way to script access to file's metadata without actually opening the binary image data into Photoshop?

Likes

translate

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
Adobe Community Professional ,
Apr 25, 2021 Apr 25, 2021

Copy link to clipboard

Copied

XMP based metadata can reside directly in the file (subject to file format specifications), or in the case of proprietary raw camera file format data (.CR2, .NEF, .ORF etc) it can be stored in a "sidecar" file. So yes, it is possible to directly access the embedded metadata without opening the binary image data. Have you tried the code above or the code in the links provided (some code is read only, some write)?

Likes

translate

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