Skip to main content
edvardkrupke
Known Participant
October 2, 2019
Question

Accessing OriginalRawFileName through xmp?

  • October 2, 2019
  • 5 replies
  • 1332 views

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!

This topic has been closed for replies.

5 replies

Stephen Marsh
Community Expert
Community Expert
October 3, 2019

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);  
//////////////  
}

 

 

edvardkrupke
Known Participant
October 3, 2019
This is just brilliant. I guess I'll have to credit both you and SuperMerlin - thank you so much, it does exactly what I want!
Stephen Marsh
Community Expert
Community Expert
October 3, 2019

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);  
//////////////  
 
}

 

 

edvardkrupke
Known Participant
October 3, 2019

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!

Stephen Marsh
Community Expert
Community Expert
October 3, 2019
It is right there in the raw metadata of any file processed through ACR…Then it is just a matter of matching the name space. Of course, more than that is required but it was a start.
Kukurykus
Legend
October 2, 2019
edvardkrupke
Known Participant
October 3, 2019
Yes!:) Great work you do over at PS-Scripts btw!
Legend
October 2, 2019

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>

Stephen Marsh
Community Expert
Community Expert
October 2, 2019
RawFileName “naturally” exists in any file processed through ACR. PreservedFileName is obviously set by Bridge using the Batch Rename tool. What if a raw file has not been touched by either ACR or Bridge?
edvardkrupke
Known Participant
October 3, 2019
The images will probably get handled via Bridge, but since I am buildning a script to handle everything automatically, I'd like to have it as a stand-alone function:/
Stephen Marsh
Community Expert
Community Expert
October 2, 2019

I'm guessing part of the answer may be:

 

(XMPConst.NS_CAMERA_RAW,"RawFileName")

 

However, I'm probably wrong.

edvardkrupke
Known Participant
October 3, 2019
Well it's at least logical - but I don't know how to use it yet:/