6 Replies Latest reply on Aug 28, 2011 3:01 AM by ldflkbuc943894353221

    Beginners question, how to use script?

    ldflkbuc943894353221 Level 1

      Hi there

       

      Im on OSX, ID4, soon upgrading to ID5.5

       

      I've been looking for a way to automatically add metadata (author) to a document/exported PDF.

      So i found this http://forums.adobe.com/message/3443064 - looks like the answer I'm seeking, but how do i actually put that into use? Where/how to i add the script?

       

      Can it be run upon opening/creating a new document, or upon exporting to PDF?

       

      I'm an experienced indesign user, and I've done some visual basic, php before. But haven't used scripting in InDesign.

       

      Any pointers in the right direction is greatly appreciated. Thanks.

       

      - Lasse Fernov

        • 1. Re: Beginners question, how to use script?
          John Hawkinson Level 5

          Hello, ldflkbuc943894353221:

           

            tomaxxi's script in the thread you cite isn't really a normal script. It is a script that installs an event handler that is automatically triggered every time you create a new document in InDesign, suhc as with File > New.

           

          You would save that file as, perhaps, tomaxxiAddXMP.jsx, and then you have some choices. You can just drop it in the User Scripts folder, according to http://www.danrodney.com/scripts/directions-installingscripts.html. At which point you would have to run it once per session (from the Scripts panel, after which point all subsequently created documents would have that happen.

           

          Alternatively, you might want to use it as a startup script. This is an OK idea, except that it might violate your expectations and surprise you sometime if you forget about it. If you follow the above instructions, instead of installing it in the "Scripts Panel" directory, you would go one level up (to "Scripts") and create a directory called "Startup Scripts" and place it there.

           

          Then restart InDesign. It will then always run whenever InDesign starts.

          • 2. Re: Beginners question, how to use script?
            ldflkbuc943894353221 Level 1

            Nice, thank you! It works "right out the box"...  that's a rare one for me

             

            I placed it in Startup Scripts, and added afterOpen to the script so my older documents also gets the metadata.


                var myEvent = app.addEventListener("afterOpen", addXMP);

             

            Hmm maybe i should edit it so i can see who created the doc, and who opened it last... wow this adds a bunch of possibilities. Thanks again

            • 3. Re: Beginners question, how to use script?
              John Hawkinson Level 5

              Good for you, though I think the afterOpen hook is bad idea -- what if a colleague sends you a document for review, you make some small changes, and send it back to him. You may be obliterating information in the Author section of his metadata without even knowing it, and he might not notice.

               

              You could add a confirmation dialog for that case. But I would think you would just be better off only changing the metadata on opened

              documents in a deliberate step.

               

              Up to you of course! The power of scripting! But "with great power comes great responsibility."

              • 4. Re: Beginners question, how to use script?
                ldflkbuc943894353221 Level 1

                I know, that is a good point. I was thinking I'd add my initials to the keywords. Do you happen to know if its possible to add a keyword, that is, append metadata instead of replacing it?

                 

                Maybe i can save the current keywords to a variable, add my initials, and then update the metadata?

                 

                (hmm i know that's gonna be a long list of keywords if i open/close the doc multiple times. Still it might be what I'm looking for)

                • 5. Re: Beginners question, how to use script?
                  John Hawkinson Level 5
                  I know, that is a good point. I was thinking I'd add my initials to the keywords. Do you happen to know if its possible to add a keyword, that is, append metadata instead of replacing it?

                  Sure. Like any JavaScript variable, you can say foo=foo+"bar"; or just plain foo+="bar";.

                   

                  Maybe i can save the current keywords to a variable, add my initials, and then update the metadata?

                  (hmm i know that's gonna be a long list of keywords if i open/close the doc multiple times. Still it might be what I'm looking for)

                  I still don't think it's a good idea, but you could check to see if your initials were already in the variable, and only thenappend to it.

                  But I think afterOpen hooks that modify the document in non-obvious ways violate the principle of least astonishment. Maybe if you added alert("Changed the author to ldflkbuc943894353221 -- but my friends call me George"); that would help. But it still makes me queasy.

                   

                  Heck, even afterNew hooks scare me, but not as badly.

                  • 6. Re: Beginners question, how to use script?
                    ldflkbuc943894353221 Level 1

                    Thanks i got it working now. But since keywords is an array I'm using push() to add to it

                    So now i can see who created the doc, and who worked on it, and in which order.

                     

                    Oh btw, i know ldflkbuc943894353221 is a silly name but I tried a lot of different names that it wouldn't accept - so i ended up just hitting a punch of characters