16 Replies Latest reply on Feb 11, 2018 2:26 PM by Kukurykus

    Creating a note/annotation in Photoshop

    MFreemanRKS Level 1

      I am working on a script that needs to be run on every file I work with.  I have an action that does what I need it to, however I would like a way to document in the photoshop file that the action has been run.  Since the action might need to be done multiple times per file, it would be ideal if the note would store some information so for future reference I can see what folders the action has been run on and how many times the action has been run.


      The action works just fine, I know how to make the action call up the script I need.  I can create all the variables I need to fill the note with the information I want.  I just cant find the script for creating a note/annotation and filling the note with the desired text.


      Is this even possible?

        • 1. Re: Creating a note/annotation in Photoshop
          Kukurykus Adobe Community Professional

          Do you need metadata information separate for every file (stored in these certain files), or you need one other text file where are gathered informations about all processed files? So one note per each file nested in their metadas, or one note for all files saved somewhere on disk?

          • 2. Re: Creating a note/annotation in Photoshop
            MFreemanRKS Level 1

            creating a note in the photoshop file using the note tool would be ideal.  Current work around I have going is  just making a new text layer with the information I need and hiding it at the bottom of the file. 

            • 3. Re: Creating a note/annotation in Photoshop
              Kukurykus Adobe Community Professional

              Recently I have read something that placing (or reading or both) notes is not scriptable, however Mike Hall found some way to do it, but I didn't focus deeply on his workaround and now I don't remember where I have seen it. Later i'll check it, what way that could be done (if I find it, but probably that had something to do with Extensible Metadata Platform).


              Do you use Adobe Bridge? There you have Labels (5 colours) and Ratings (up to 5). They can be used to inform you about specific information for you. They would be more like symbols you undrstand your way. As workaround also file names can be changed like from someName.psd to someName_10.jpg what means this file was processed 10 times.


              Just in case that wasn't possible you ask for, list all info you need to store in notes (times something happened, processed folders, ???), maybe they can be displayed other way, not by those notes but other depending what kind of info they are...


              I never used annotation, but now I checked ScriptListener records them, so maybe there is a chance to do what you wish...

              • 4. Re: Creating a note/annotation in Photoshop
                pixxxel schubser MVP & Adobe Community Professional



                how about this

                // Create a new note at position x,y
                function makeAnnotation(posX,posY) {
                  function cTID(s) { return app.charIDToTypeID(s); };
                  function sTID(s) { return app.stringIDToTypeID(s); };
                    var desc30 = new ActionDescriptor();
                        var ref12 = new ActionReference();
                        ref12.putClass( sTID('annotation') );
                    desc30.putReference( cTID('null'), ref12 );
                        var desc31 = new ActionDescriptor();
                            var desc32 = new ActionDescriptor();
                            desc32.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), posX );
                            desc32.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), posY );
                        desc31.putObject( cTID('Lctn'), cTID('Pnt '), desc32 );
                            var desc33 = new ActionDescriptor();
                            desc33.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 240.000000 );
                            desc33.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 140.000000 );
                        desc31.putObject( cTID('Sz  '), cTID('Ofst'), desc33 );
                        desc31.putEnumerated( sTID('annotType'), sTID('annotType'), sTID('annotText') );
                    desc30.putObject( cTID('Usng'), sTID('annotation'), desc31 );
                    executeAction( cTID('Mk  '), desc30, DialogModes.NO );


                and this

                // Insert text in this created note
                var idsetd = charIDToTypeID( "setd" );
                    var desc58 = new ActionDescriptor();
                    var idnull = charIDToTypeID( "null" );
                        var ref12 = new ActionReference();
                        var idannotation = stringIDToTypeID( "annotation" );
                        ref12.putIndex( idannotation, 0 ); // the number/index of note
                    desc58.putReference( idnull, ref12 );
                    var idT = charIDToTypeID( "T   " );
                        var desc59 = new ActionDescriptor();
                        var idTxtD = charIDToTypeID( "TxtD" );
                        desc59.putData( idTxtD, String.fromCharCode( 255, 254, 116, 0, 104, 0, 105, 0, 115, 0, 32, 0, 105, 0, 115, 0, 32, 0, 116, 0, 101, 0, 120, 0, 116, 0, 32, 0, 105, 0, 110, 0, 
                32, 0, 97, 0, 32, 0, 110, 0, 111, 0, 116, 0, 101, 0 ) );
                        var idtext = stringIDToTypeID( "text" );
                        desc59.putString( idtext, """this is text in a note""" );
                    var idannotation = stringIDToTypeID( "annotation" );
                    desc58.putObject( idT, idannotation, desc59 );
                executeAction( idsetd, desc58, DialogModes.NO );



                • 5. Re: Creating a note/annotation in Photoshop
                  Jarda Bereza Level 4

                  Is there way, how to read annotations?

                  • 6. Re: Creating a note/annotation in Photoshop
                    Kukurykus Adobe Community Professional

                    MFreemanRKS, you find an answer in created by you Create notes/annotations? - PS-SCRIPTS.COM topic on that forum.

                    • 7. Re: Creating a note/annotation in Photoshop
                      Pedro Cortez Marques Level 3

                      Until now, I couldn't find a way of read annotations. Only deleting and creating them.


                      Although, the annotation can be passed to a photoshop PDF and converted in the PDF localized notes! This means there is a way of retrieving the annotations content but on an another level that is not scripting.

                      • 8. Re: Creating a note/annotation in Photoshop
                        r-bin Level 5

                        Hacker way )

                        When the file is saved (if the anotations changed you need to save the file, you do not need to close it), you can open the binary document file through the script and find the "8BIMAnno" tag. After it you will find the structure from which you can pull out the number of annotations, and by the tags "txtC" and "txtA" pull out the text and the author of the annotations.

                        • 9. Re: Creating a note/annotation in Photoshop
                          r-bin Level 5

                          Very simplistic but working example )


                          var file = new File(app.activeDocument.fullName);
                          file.encoding = "BINARY";
                          if (file.error) { alert(file.error); executeAction( stringIDToTypeID( "stop" ), undefined, DialogModes.NO ); }
                          var block_size = 10000;
                          var len = file.length/block_size;
                          for (var i = 0; i < len; i++)
                              var buff = file.read(block_size);
                              var n = buff.indexOf("8BIMAnno");
                              if (n >= 0)
                                  var s = buff.substr(n)
                                  var n = s.indexOf("txtC");
                                  if (n >= 0)
                                      s = s.substr(n+10);
                                      var txt = "";
                                      for (var x = 0; x < 200; x+=2)
                                          txt += String.fromCharCode(256*s.charCodeAt(x) + s.charCodeAt(x+1));
                                      alert("Found annotation:\n\n" + txt);    
                          2 people found this helpful
                          • 10. Re: Creating a note/annotation in Photoshop
                            Kukurykus Adobe Community Professional

                            It works however when I run it from ExtendScript ToolKit it doesn't finish its work after 'Done' is alerted. ESKT gets frozen. Blue stop icon is still active, but can not be used to stop the script. Only closing ESKT helps. And btw there are added four chinese letters to end of annotation.

                            • 11. Re: Creating a note/annotation in Photoshop
                              r-bin Level 5

                              The length of the text is in the next 4 bytes after the txtC tag. I'm too lazy to write a full code. It's just an idea that I myself do not need. )

                              • 12. Re: Creating a note/annotation in Photoshop
                                Jarda Bereza Level 4

                                Parsing file like this easy to write but bad thing may happen.

                                You should first to read lenght of PSD header then length of subsection and so on and pick only needed data instead parsing all.


                                Adobe Photoshop File Formats Specification


                                Check xbytor script which reads actions files and can convert them into XML ect.

                                There are methods for reading binary files.

                                • 13. Re: Creating a note/annotation in Photoshop
                                  Chuck Uebele Adobe Community Professional & MVP

                                  What about storing the information you want in a custom metadata field that can either be read by another script, creating a custom metadata panel, or by looking at the raw file data?

                                  • 14. Re: Creating a note/annotation in Photoshop
                                    MFreemanRKS Level 1

                                    sorry about radio silence, been on vacation from work.  I am looking into all of your responses.  Thank you so much for all of your help thus far, I'm sure something in here will do what I need!

                                    • 15. Re: Creating a note/annotation in Photoshop
                                      MFreemanRKS Level 1

                                      The script from there is actually really close to what I need.  The only thing that I am having problems with is this script deletes the notes that are already in the file.   Where in that script are you adding the information "# and working"  into the note?


                                      Thank You!

                                      • 16. Re: Creating a note/annotation in Photoshop
                                        Kukurykus Adobe Community Professional

                                        I will look into it today to see what I can do, as that was some time ago I wrote it and not remember well how that worked.




                                        Another first of this kind script you will not find other like it on this and Create notes/annotations? - PS-SCRIPTS.COM forums (and probably nowhere ). It works extremaly fast with even many channels, paths and layer(Set)s beside notes. Only first time it takes 1/5 second while every next just 100 ms (40 for saving, 25 reading, and 20 for searching by RegEx).


                                        For those who didn't read earlier posts: you can record this script as last item of your action. It's going to create 'note' with number of times a file was processed and name of its parent folder (remove .name in aD.path.name if you want full path).


                                        $.level = 0; try {
                                             pth = (aD = activeDocument).path; function sTT(v) {return stringIDToTypeID(v)}
                                             with(psd = new PhotoshopSaveOptions()) {
                                                  annotations = !(alphaChannels = embedColorProfile = layers = spotColors = false)
                                             aD.saveAs(fle = File('~/desktop/.psd'), psd, true)
                                             function anno() {
                                                  fle.open('r'); var r = fle.read(); fle.close(), fle.remove()
                                                  var r = r.match(/txtC.{3,6}(\n.{2})?((?:\x00.)+)?/g)
                                                  if (r) {for(i = 0; i < l = r.length; i++) {
                                                       if (n = r[i].slice(10, i == l - 1 ? r[i].length : -4).match(/[^\x00]/g))
                                                       {if (/#\d+/.test(n = n.join(''))) return parseFloat(n.slice(1)) + 1}
                                             if (arr = ['horizontal', 'vertical'], !(n = anno())) {
                                                  (ref1 = new ActionReference()).putClass(sTT('annotation'));
                                                  (dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1)
                                                  u = (p = preferences).rulerUnits, p.rulerUnits = Units.PIXELS
                                                  for(dsc3 = new ActionDescriptor(), j = 0; j < arr.length; j++) {
                                                       dsc3.putUnitDouble(sTT(arr[j]), sTT('pixelsUnit'),
                                                       eval('aD.' + (!j ? 'width' : 'height') +'.value * 19 / 20'))
                                                  } p.rulerUnits = u;
                                                  (dsc2 = new ActionDescriptor()).putObject(sTT('location'), sTT('paint'), dsc3)
                                                  dsc2.putEnumerated(aT = sTT('annotType'), aT, sTT('annotText')), dsc1.putObject
                                                  (sTT('using'), sTT('annotation'), dsc2), executeAction(sTT('make'), dsc1, DialogModes.NO);
                                             number = '#' + (n || 0) + ' & ' + pth.name;
                                             (ref1 = new ActionReference()).putIndex(sTT('annotation'), i); (dsc1 = new ActionDescriptor())
                                             .putReference(sTT('null'), ref1); (dsc2 = new ActionDescriptor()).putString(sTT('text'), number)
                                             dsc1.putObject(sTT('to'), sTT('annotation'), dsc2), executeAction(sTT('set'), dsc1, DialogModes.NO)
                                        catch (err) {alert(err.message)}