Copy link to clipboard
Copied
Hi
I've been having problems with client changing file names when sending back amends and not knowing which job or version the file relates to.
Is there a simple script which will insert the file name into the document title metadata field? Or it could go into the descriptin field if easier. That way even if they chage the file title I can still find the original job title
On save/export would be great if possible?
Thanks so much!
Copy link to clipboard
Copied
Have a look at: File > File Info, to see if that would be of any help.
Copy link to clipboard
Copied
Perhaps you can put together a solution from this previous post: https://community.adobe.com/t5/indesign/scripts-to-insert-metadata-automatically-to-document-with-pa...
Copy link to clipboard
Copied
This has actually come up before. You can try saving this script into your Scripts>startup scripts folder and restart ID:
var el = app.eventListeners.add("afterSave", onSaveKW );
/**
* Function to run after a Save
* the event
*/
function onSaveKW(evt){
var kws = app.activeDocument.metadataPreferences.keywords;
var kwp = "oname"
var n = evt.parent.name
if (!checkKeywords(kws, kwp)) {
kws.unshift("oname:" + n)
app.activeDocument.metadataPreferences.keywords = kws
}
}
/**
* Checks if a keyword starting with oname: exists
* the keyword array to check
* the prefix string
* false if keyword does not exist
*
*/
function checkKeywords(a, p){
var b = false
for (var i = 0; i < a.length; i++){
if (a[i].split(":")[0] == p) {
b=true
}
}
return b
}
The startup script listens for an after save event, and sets the doc name as a keyword, if it’s the first save the name gets added as oname:YourFileName.indd.
Here I created a new file and named it MyIDFile.indd and then did a save as with a different name and the file info keeps the original name:
Copy link to clipboard
Copied
Also, the downside of saving the original name as a keyword, is the client could edit the keywords after the name change. If that’s a potential problem the original name could be inserted into the RAW XMP data as a custom node:
Copy link to clipboard
Copied
Hello @ChristianAsprenoGLOBE
The below script will write the file name into the document title field every time the document is Saved or Save As.
Save this script here: Applications ▸ Adobe InDesign ▸ Scripts ▸ startup scripts folder and restart Indesign:
#targetengine "session"
function saveFileMetaData() {
if(app.layoutWindows.length == 0) return;
else if (!app.activeDocument.saved) {
alert('Sorry, there was a problem and the document was not saved.');
return;
}
doc = app.activeDocument;
var fileName = doc.name.replace(/.indd$/i, "");
var myMetaData = doc.metadataPreferences;
myMetaData.documentTitle = fileName;
}
app.addEventListener('afterSave', saveFileMetaData, false);
app.addEventListener('afterSaveAs', saveFileMetaData, false);
Regards,
Mike
Copy link to clipboard
Copied
Hi @Mike Bro, I think @ChristianAsprenoGLOBE wants the original file name saved to metadata—the current file name (doc.name) could be different.
Copy link to clipboard
Copied
Hi @rob day
I see you point, but if the script is only installed on the OP's computer the document title meta data would be whatever they last Saved or Saved As before sending the file off to their client.
Regards,
Mike
Copy link to clipboard
Copied
Thanks all! Im going to give this one a try now and will let you know the results. I think the document title is what we're after so it sounds perfect!
Copy link to clipboard
Copied
This is really useful, thanks!