Copy link to clipboard
Copied
Hello everyone,
I'm using windows 10 and I have a file with a tag on its metadata:
Here is how it looks on Photoshop:
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.
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
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.
I'm 99% sure this can be done as well in Photoshop.
Copy link to clipboard
Copied
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.
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) { }
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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) { }
Copy link to clipboard
Copied
Thank you – that works as expected, cheers!
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.
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?
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)?