Reputation: 69
I am looking for a script can check Physical file id of a document and compare it to another one. For example, I have some images named xxx_01.tif
, xxx_02.tif
... (they already had their own Raw data), I always need to save as a swatch (named xxx_sw.tif
) from xxx_01
file to keep the Raw data but sometimes I created from xxx_02
and it didn't match.
Is there any way to check and alert if "Physical file id" of sw file doesn't match to 01's ?
Reply @GhoulFool:
var srcDoc = app.activeDocument;
var ctpath = srcDoc.path;
var ctname = srcDoc.name
var rawData1 = srcDoc.xmpMetadata.rawData;
var idCT = find_original_document_ID(rawData1);
function find_original_document_ID(str)
{
var regEx = new RegExp(".+xmpMM:OriginalDocumentID.+", "gim");
var result = str.match(regEx);
if (result != null)
{
return result;
}
}
File(ctpath)
.getFiles(function(v) {v.name.indexOf('_bustfront1') + 1 && open(v)})
var doc2 = app.activeDocument;
var fName = doc2.name;
var rawData2 = doc2.xmpMetadata.rawData;
//alert(rawData);
var id01 = find_original_document_ID(rawData2);
function find_original_document_ID(str)
{
var regEx = new RegExp(".+xmpMM:OriginalDocumentID.+", "gim");
var result = str.match(regEx);
if (result != null)
{
return result;
}
}
doc2.close();
// I am stuck here, alert always shows even it true or false
if (idCT == id01) {}
else {alert (ctname + idCT + '\n' + '\n' + fName + id01)}
Upvotes: 0
Views: 103
Reputation: 6967
If by phyiscal id you mean OriginalDocumentID then yes It can be found with app.activeDocument.xmpMetadata.rawData
There are probably better ways to get the ID from the XML, but you get the idea.
// call the source document
var srcDoc = app.activeDocument;
var rawData = srcDoc.xmpMetadata.rawData;
//alert(rawData);
var id = find_original_document_ID(rawData);
alert(id);
function find_original_document_ID(str)
{
var regEx = new RegExp("\<xmpMM\:DocumentID.+", "gim"); //whole line
var result = str.match(regEx);
if (result != null)
{
alert(result);
var justID = result.toString();
// <xmpMM:DocumentID>xmp.did:8731d1f4-07fb-084b-b66c-ecd397cc0b21</xmpMM:DocumentID>
// <xmpMM:DocumentID>adobe:docid:photoshop:2ca50ad0-bdcb-534e-8720-4d1f0f32fe9c</xmpMM:DocumentID>
justID = justID.replace(/\<\/?xmpMM\:DocumentID\>/g, "");
return justID;
}
}
It should just be a matter of comparing ID1 == ID2 after that.
Upvotes: 0