Convert all notes/annotations to text layers in Photoshop scripting
Hey!
Does anyone have an existing script for converting all notes/annotations to text layers?
It can be all notes to a single text layer or multiple.
I currently have a script to select all text layers, send them to a group, search their contents for keywords, and create a txt file if they contain the keywords. I am looking to add a snippet of code to the top of this script in order to cover the off chance a note/annotation was used instead of a text layer.
Looking through the Adobe Javascript Ref 2020 document, I did not see anything in the native DOM for adobe, so I am assuming this will be an AM event.
If it helps, here is the code for creating a note I copied from ScriptListener/Clean SL.
select3(true, true);
function select3(dontRecord, forceNotify) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putClass( s2t( "textAnnotTool" ));
descriptor.putReference( c2t( "null" ), reference );
descriptor.putBoolean( s2t( "dontRecord" ), dontRecord );
descriptor.putBoolean( s2t( "forceNotify" ), forceNotify );
executeAction( s2t( "select" ), descriptor, DialogModes.NO );
}
// =======================================================
historyStateChanged2(645, "New Note", true, 2);
function historyStateChanged2(ID, name2, hasEnglish, itemIndex) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
descriptor.putInteger( s2t( "documentID" ), 621 );
descriptor.putInteger( s2t( "ID" ), ID );
descriptor.putString( s2t( "name" ), name2 );
descriptor.putBoolean( s2t( "hasEnglish" ), hasEnglish );
descriptor.putInteger( s2t( "itemIndex" ), itemIndex );
executeAction( s2t( "historyStateChanged" ), descriptor, DialogModes.NO );
}
// =======================================================
make(521, 659, 240, 140);
function make(horizontal, vertical, horizontal2, vertical2) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var descriptor3 = new ActionDescriptor();
var descriptor4 = new ActionDescriptor();
var reference = new ActionReference();
reference.putClass( s2t( "annotation" ));
descriptor.putReference( c2t( "null" ), reference );
descriptor3.putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), horizontal );
descriptor3.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), vertical );
descriptor2.putObject( s2t( "location" ), c2t( "Pnt " ), descriptor3 );
descriptor4.putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), horizontal2 );
descriptor4.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), vertical2 );
descriptor2.putObject( s2t( "size" ), s2t( "offset" ), descriptor4 );
descriptor2.putEnumerated( s2t( "annotType" ), s2t( "annotType" ), s2t( "annotText" ));
descriptor.putObject( s2t( "using" ), s2t( "annotation" ), descriptor2 );
executeAction( s2t( "make" ), descriptor, DialogModes.NO );
}
// =======================================================
historyStateChanged3(646, "Edit Note", true, 3);
function historyStateChanged3(ID, name2, hasEnglish, itemIndex) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
descriptor.putInteger( s2t( "documentID" ), 621 );
descriptor.putInteger( s2t( "ID" ), ID );
descriptor.putString( s2t( "name" ), name2 );
descriptor.putBoolean( s2t( "hasEnglish" ), hasEnglish );
descriptor.putInteger( s2t( "itemIndex" ), itemIndex );
executeAction( s2t( "historyStateChanged" ), descriptor, DialogModes.NO );
}
// =======================================================
set("TEXT\r");
function set(text) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putIndex( s2t( "annotation" ), 0 );
descriptor.putReference( c2t( "null" ), reference );
descriptor2.putData( s2t( "textData" ), String.fromCharCode( 255, 254, 84, 0, 69, 0, 88, 0, 84, 0, 13, 0 ) );
descriptor2.putString( s2t( "text" ), text );
descriptor.putObject( s2t( "to" ), s2t( "annotation" ), descriptor2 );
executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}