Copy link to clipboard
Copied
Hi!
I am having trouble with accessing the XMP OriginalRawFileName - can anyone help me?
I need to be able to read what the original filename of a picture is, and figured this would be easiest to solve by looking at the xmp data, but I can't even read that properly - I am obviously doing something wrong.
SuperMerlin wrote this, and I tried just copy/pasting it - but I cannot get a result even from the unmodified original code;
#target photoshop;
if(documents.length){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
var shadow = xmp.getProperty(XMPConst.NS_CAMERA_RAW,"ParametricShadowSplit");
var exposureValue = xmp.getProperty(XMPConst.NS_CAMERA_RAW, "Exposure");
var keys = getArrayItems(XMPConst.NS_DC,'subject');
for(var a in keys){
//amend the match for your keywod
if(keys.toString().match(/key1/)){
//things to do if keyword found
alert("keyword found");
break;
}
}
};
function getArrayItems(ns, prop){
var arrItem=[];
var items = xmp.countArrayItems(ns, prop);
for(var i = 1;i <= items;i++){
arrItem.push(xmp.getArrayItem(ns, prop, i));
}
return arrItem;
};
So - how would one modify the above (or write new code) to access the OriginalRawFileName?
Thank you in advance!
Copy link to clipboard
Copied
I'm guessing part of the answer may be:
(XMPConst.NS_CAMERA_RAW,"RawFileName")
However, I'm probably wrong.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I just did a Batch Rename in Bridge with Preserve current filename checked. This is the tag and namespace. I'd look there.
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
<xmpMM:PreservedFileName>foo.CR2</xmpMM:PreservedFileName>
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Is that you? Getting EXIF field "OriginalRawFileName"?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I modified a script by Dan Ebberts found here.
It detects raw filename on jpgs saved from a RAW, but you need to open them manually - I cannot get it to work on the current file (activeDocument) though - will try to solve it tomorrow if I have time to have a look on it then...
Here's what I've got right now;
try {
var metaFile = File.openDialog("Select file to import.");
var xmpFile = new XMPFile( metaFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_READ);
var xmp = xmpFile.getXMP();
var RAWFileName = xmp.getProperty(XMPConst.NS_CAMERA_RAW,"RawFileName");
try {
alert("Found Raw Filename:\n" + RAWFileName.toString());
}
catch(error) {
alert("No Raw Filename could be found.");
}
} catch(error) {
alert("Something seems to have gone wrong.\n" + error);
}
Thank you Stephen_A_Marsh for finding (XMPConst.NS_CAMERA_RAW,"RawFileName") for me!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Try this:
#target photoshop;
//community.adobe.com/t5/Photoshop/Accessing-OriginalRawFileName-through-xmp/m-p/10647387#M266922
//Accessing OriginalRawFileName through xmp?
//estk.aenhancers.com/10%20-%20Scripting%20Access%20to%20XMP%20Metadata/accessing-the-xmp-scripting-api.html
//forums.adobe.com/message/10315559#10315559
//Help with script to read specific XMP metadata in an image - Credit to SuperMerlin
//community.adobe.com/t5/Photoshop/Help-with-script-to-read-specific-XMP-metadata-in-an-image/m-p/9859270#M169875
//community.adobe.com/t5/Photoshop/Help-with-script-to-read-specific-XMP-metadata-in-an-image/m-p/9859271#M169876
if(documents.length){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
var RFN = xmp.getProperty(XMPConst.NS_CAMERA_RAW,"RawFileName");
/////////////////// Do with as you wish
alert(RFN);
//////////////
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
My pleasure, it is a great way for me to learn! Here is a variation to remove the filename extension:
#target photoshop;
//community.adobe.com/t5/Photoshop/Accessing-OriginalRawFileName-through-xmp/m-p/10647387#M266922
//Accessing OriginalRawFileName through xmp?
//estk.aenhancers.com/10%20-%20Scripting%20Access%20to%20XMP%20Metadata/accessing-the-xmp-scripting-api.html
//forums.adobe.com/message/10315559#10315559
//Help with script to read specific XMP metadata in an image - Credit to SuperMerlin
//community.adobe.com/t5/Photoshop/Help-with-script-to-read-specific-XMP-metadata-in-an-image/m-p/9859270#M169875
//community.adobe.com/t5/Photoshop/Help-with-script-to-read-specific-XMP-metadata-in-an-image/m-p/9859271#M169876
if(documents.length){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
var RFN = xmp.getProperty(XMPConst.NS_CAMERA_RAW,"RawFileName");
// var RFN2 = RFN.toString().split(".", 1) // remove extension
var RFN2 = RFN.toString().replace(/\.[^\.]+$/, ''); // remove extension
/////////////////// Do with as you wish
alert(RFN2);
//////////////
}