Skip to main content
Known Participant
November 17, 2022
Question

Convert Annotations/Notes to text layers, Photoshop Scripting

  • November 17, 2022
  • 0 replies
  • 107 views

Hey! 

Does anyone have a script to covert annotations/notes from the notes panel in Photoshop to text layers? I currently have a script to select all text layers, create a group of them, send them to the front of the document, create a string varaible of all of their contents, and search it for substring. I just want to add a snippet of code before the other steps to convert all notes/annotations to text layers. Searching through Adobe's Javscript Ref 2020 document, I did not see much on Annotations/notes, so I am assuming this is probably going to have to be an AM process?

Any insight would be helpful, thanks!

If it helps this is the code I have for making a note from Scripting Listener and CLEAN-SL

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 );

 

This topic has been closed for replies.