Create notes/annotations?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

mfreeman
Posts: 1
Joined: Wed Dec 20, 2017 4:45 pm

Create notes/annotations?

Post by mfreeman »

I cant seem to find any resources on how to create a note within photoshop using scripts. I know the note tool exists but Is it even possible to make one with scripting?

I essentially need something that can take the currently selected folder and make a note with that folder name within the note. I have the variable for the folder name ready to go, just the note part I'm struggling to find info on.

Still relatively new, anything can help!

Thank You!!
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Create notes/annotations?

Post by Kukurykus »

What does it do:

- deletes all annotations from a document
- creates new annotation in bottom right corner
- adds new content (times that was processed and path)

To use it, do as you planned. Set it as last item of your action.
Every time it's ran it increases number in annotation & adds a parent folder name:

Code: Select all

function sTT(v) {return stringIDToTypeID(v)} preferences.rulerUnits = Units.PIXELS

nAD = 'new ActionDescriptor()', iT = (aD = activeDocument).info.title
executeAction(sTT('deleteAllAnnot'), eval(nAD), DMN = DialogModes.NO);

(ref1 = new ActionReference()).putClass(ant = sTT('annotation'));
(dsc1 =eval(nAD)).putReference(sTT('null'), ref1); for(dsc3 = eval
(nAD), i = 0; i < (arr = ['horizontal', 'vertical']).length; i++) {
dsc3.putUnitDouble(sTT(arr[i]), sTT('pixelsUnit'), eval
('aD.' + (!i ? 'width' : 'height') +'.value * 19 / 20'))
}
(dsc2 = eval(nAD)).putObject(sTT('location'), sTT('paint'), dsc3);
dsc2.putEnumerated(aT = sTT('annotType'), aT, sTT('annotText')), dsc1.
putObject(sTT('using'), ant, dsc2), executeAction(sTT('make'), dsc1, DMN);

(ref1 = new ActionReference()).putIndex(ant, 0);
(dsc1 = eval(nAD)).putReference(sTT('null'), ref1);
(dsc2 = eval(nAD)).putString(sTT('text'), aD.info.title =
(!iT ? +iT : +iT + 1) + ' & ' + aD.path.name), dsc1.putObject
(sTT('to'), ant, dsc2), executeAction(sTT('set'), dsc1, DMN)

Another approach. This time script works other way, and don't delete all annotations to recrate the most needed:

Code: Select all

$.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)}
Attachments
Annotation 2.rar
(1.08 KiB) Downloaded 322 times
Annotation.rar
(770 Bytes) Downloaded 345 times