Skip to main content
MFreemanRKS
Participating Frequently
December 20, 2017
Question

Creating a note/annotation in Photoshop

  • December 20, 2017
  • 5 replies
  • 6313 views

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?

This topic has been closed for replies.

5 replies

MFreemanRKS
Participating Frequently
January 2, 2018

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!

Chuck Uebele
Community Expert
Community Expert
December 22, 2017

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?

Jarda Bereza
Inspiring
December 22, 2017

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.

Jarda Bereza
Inspiring
December 20, 2017

Is there way, how to read annotations?

Pedro Cortez Marques
Legend
December 22, 2017

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.

Legend
December 22, 2017

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.

Kukurykus
Legend
December 20, 2017

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?

MFreemanRKS
Participating Frequently
December 20, 2017

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. 

Kukurykus
Legend
February 11, 2018

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!


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.

EDIT:

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.slice(10, i == l - 1 ? r.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), 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)}