• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

adding name of indesign document to metadata of all images used in document

Explorer ,
Sep 19, 2014 Sep 19, 2014

Copy link to clipboard

Copied

I have been asked to include the indesign file name in the metatag of each image used in every document i produce from here on.

is there a way to write a script in indesign that will copy the document name then open every link (in bridge?) and append the document name to the metadata (i don't want to lose any existing tags) and then save?

scott

TOPICS
Scripting

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 20, 2014 Sep 20, 2014

Copy link to clipboard

Copied

Hi,

Looks like a complex issue. Possibly time-intensive.

But possible using BridgeTalk, I guess.

Jarek

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2014 Sep 20, 2014

Copy link to clipboard

Copied

Hm?!

And should the name be removed, if the image is removed from the InDesign document?

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 20, 2014 Sep 20, 2014

Copy link to clipboard

Copied

How about InDesign documents with the same name at different locations?

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 21, 2014 Sep 21, 2014

Copy link to clipboard

Copied

Before you start with BridgeTalk, have a look at the JavaScript Tools Guide, the chapter about the "XMPScript" code library.

With that requirement I would write a startup script to listen for link related events and maintain the image files accordingly - that way you could even "unsubscribe" removed links as long the image is still around. For completeness sake also handle the document open, save, revert events to take care of preexisting, foreign, newly created (untitled) or renamed InDesign documents.


Of course you have to keep in mind that changing XMP will modify the image files and thus require to update the links, so you'd better check whether the data is already present and then don't touch the file. Anyway your admin will love the exploding storage requirements in backup when fat image files start to multiply per use.


A less obtrusive way for image usage reports would be an explicit menu call when you consider the InDesign document "produced" in the sense of the requirement, and then submit an additional file for the InDesign document to wherever that info is handled.


Dirk


Edit: some more document events to consider 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 21, 2014 Sep 21, 2014

Copy link to clipboard

Copied

This should should give you a start. It'll add the active documents name to the field instructions of the img when executed. Tested once. No errorhandling.

currDoc = app.activeDocument;

docName = currDoc.name;

docGraphics = currDoc.allGraphics;

for(var g = 0; g < docGraphics.length; g++){

    currGraphic = docGraphics;

        currGraphicFilePath = currGraphic.itemLink.filePath;

        fileObject = File(currGraphicFilePath);

writeDocNameToMeta(fileObject, docName);

    }

function writeDocNameToMeta(fileObject, docName){

if(loadXMPLibrary()){

        var myFile = fileObject;

        xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

        var myXmp = xmpFile.getXMP();

              var myStatus = myXmp.getProperty(XMPConst.NS_PHOTOSHOP,"Instructions");

   myXmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Instructions");

   myXmp.setProperty(XMPConst.NS_PHOTOSHOP, "Instructions", docName);

  

 

   if (xmpFile.canPutXMP(myXmp)) {          xmpFile.putXMP(myXmp);    }

     

        xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

        unloadXMPLibrary();

    }

}

    function loadXMPLibrary(){

        if ( !ExternalObject.AdobeXMPScript ){

            try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}

            catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}

        }

        return true;

    }

function unloadXMPLibrary(){

        if( ExternalObject.AdobeXMPScript ){

            try{ExternalObject.AdobeXMPScript.unload(); ExternalObject.AdobeXMPScript = undefined;}

            catch (e){alert('Unable to unload the AdobeXMPScript library!');}

        }

    }

Hans-Gerd Claßen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2014 Sep 21, 2014

Copy link to clipboard

Copied

@Hans-Gerd – interesting…
Never did stuff like that.

What will happen in a multi-user environment, if one particular image on a server is placed (removed) from several InDesign documents "at the same" time? I imagine your code plus the idea of Dirk with numerous event handlers writing "constantly" to the images. Is a clash of writing operations by opening, closing files a "likely" case? And what will happen then?

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 22, 2014 Sep 22, 2014

Copy link to clipboard

Copied

@Uwe - the original request sounded like a single user approach was sufficient. Besides I pointed out that you better avoid too frequent updates. Multi user environments should have some naming/folder conventions in place anyway so users won't collide on each other's image edits, or they will be using editorial systems.

The second part of my post - a separate report triggered by explicit menu action - works at any scale. I have a similar reporting program deployed at several sites, each with hundreds of users. As a plugin that program has a few more features and it requires a custom backend server to handle the load, but the principle remains the same.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 23, 2014 Sep 23, 2014

Copy link to clipboard

Copied

after much though to all the issues that you have brought to my attention this just seems to be a bad idea and it is being scrapped.....thanks for all the help on this failed experiment!!!!

scott

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

Hi together,

Hans-Gerd Claßen's code was damaged when this thread was moved over from the old InDesign Scripting forum to this new InDesign forum by the end of 2019. Here an update of the corrected code:

 

 

var currDoc = app.documents[0];  
var docName = currDoc.name;  
var docGraphics = currDoc.allGraphics;  
  
for(var g = 0; g < docGraphics.length; g++)
{  
	
	var currGraphic = docGraphics[g];  
	var currGraphicFilePath = currGraphic.itemLink.filePath;
	var fileObject = File(currGraphicFilePath);
	
	writeDocNameToMeta(fileObject, docName);  
}  



function writeDocNameToMeta(fileObject, docName)
{  
	if(loadXMPLibrary())
	{  
		
		var myFile = fileObject;  
		var xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);  
		var myXmp = xmpFile.getXMP();  
		var myStatus = myXmp.getProperty(XMPConst.NS_PHOTOSHOP,"Instructions"); 
		
		myXmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Instructions");   
		myXmp.setProperty(XMPConst.NS_PHOTOSHOP, "Instructions", docName);  


		if (xmpFile.canPutXMP(myXmp))
		{
			xmpFile.putXMP(myXmp);
		};

		xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);  
		unloadXMPLibrary();
		
	};
}  
  
  
function loadXMPLibrary()
{  
	if ( !ExternalObject.AdobeXMPScript )
	{  
		try{
			ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
			}
		catch(e){alert('Unable to load the AdobeXMPScript library!'); return false;}
	}  
	return true;  
}  
  
function unloadXMPLibrary()
{  
	if( ExternalObject.AdobeXMPScript )
	{  
		try{
			ExternalObject.AdobeXMPScript.unload();
			ExternalObject.AdobeXMPScript = undefined;
			}  
		catch (e){alert('Unable to unload the AdobeXMPScript library!');}  
	}  
}

 

 

Had no issue to run it on an InDesign document with one image placed with InDesign 2020 version 15.1.3.302.

 

It failed in InDesign 2021 version 16.2.1.100. And also with the now released 16.2.1.102.

Something is broken with loading the AdobeXMPScript library in InDesign 2021!

Must be a bug.

 

XMP-Script-Error-Message-1.PNG

 

Also see this thread that was posted today:


Unable to load the AdobeXMPScript library in Indesign CC 2021
Charu Rajput, Adobe Community Professional, 3 hours ago
https://community.adobe.com/t5/indesign/unable-to-load-the-adobexmpscript-library-in-indesign-cc-202...

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

The good news:

Hans-Gerd's code is still working with InDesign 16.1.0.20.

So the bug must be with 16.2.1.100 that I installed from the Prerelease tab of the CC Desktop App.

All done on Windows 10 version 2004.

 

EDIT:

The bad news:

Had the chance to test with the now released version 16.2.1.102.

Hans-Gerd's code failed.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Here is a BridgeTalk version where the doc name gets added as a keyword:

 

 

 

 

#targetengine "session" 

var doc = app.documents.item(0);
var lnks = doc.links;
var aPaths = []
var dn = doc.name

for (var i = 0; i < lnks.length; i++){ 
    if (lnks[i].parent.constructor.name == "Image") {
        aPaths.push(lnks[i].filePath)
    } 
};  

runPhotoshop(dn, aPaths);

function runPhotoshop(s, a){
    var bt = new BridgeTalk();  
    bt.target = "photoshop";  
    bt.body = "var docName = '"+s+"';\r" 
    bt.body += "var fPaths = "+a.toSource()+";\r" 
    bt.body += psScript.toString() + "psScript();";
    bt.onResult = function(resObj) {}  
    bt.onError = function( inBT ) { alert(inBT.body); };  
    bt.send(8);  
      
    function psScript() {  
        var doc; 
        var kw = new Array;
        for (var i = 0; i < fPaths.length; i++){
            doc = open(File(fPaths[i]));
            kw = doc.info.keywords;
            if (!checkItem(kw, docName)) {
                kw.push(docName)
                doc.info.keywords = kw;
                doc.save();
            } 
            doc.close();
        }; 
        
        function checkItem(a, obj) {
            for (var i = 0; i < a.length; i++) {
                if (a[i] === obj) {
                    return true;
                }
            }
            return false;
        }
    }  
}

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 08, 2021 May 08, 2021

Copy link to clipboard

Copied

Hmm, 

Bridge can do that in few clicks.

Rclick on indd / show linked files / apply filter as you want / select files you want edit / RClick and edit metadata.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

Hi Rob,

just ran your code.

 

"Error in

line 26: psScript();

Too much closing brackets."

 

ErrorCode-Script-by-RobDay.PNG

You should be able to correct the code in your post.

 

Thanks,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

Hi Uwe, I’m getting the same error when I copy the code from my post above into ExtendScript and run, but if I run the code from my saved script (it’s the same!) it works. Try my compiled version and see if it works:

 

https://shared-assets.adobe.com/link/e19092cf-ffb6-4652-6b2e-72771b0193c5

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

Yes, your script file is working when executed from the ESTK.

And the code from your post will also work, if you add a return after the last closing } after you copy it to the ESTK.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

Hmm, something odd is going on—if I copy and paste from my post and run from ESTK, the code executes and I get a too many braces error alert from inside InDesign. If I add a brace to the pasted code I get a runtime error from inside ESTK—Too many closing braces. If I delete the added brace, the code runs without an error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2021 May 12, 2021

Copy link to clipboard

Copied

LATEST

After you add a new line after the last brace the pasted code from your post is working without any error from the ESTK. The ESTK obviously needs that new line after the brace to detremine that the expression before is closed.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines