Basic Script Help

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

StudioVulcan
Posts: 1
Joined: Wed Dec 23, 2020 8:20 pm

Basic Script Help

Post by StudioVulcan »

Hi there!

New to scripting, no JS coding experience. Mostly HTML and CSS.
So, I know what I need my script to do and could do 90% of it in an action bar one thing. When it would edit a text layer, it took into account the "font" and "style" etc and with that step, all i wanted it to record was the word I was typing in, nothing else. Someone told me that a script will do what i'm after and that script listener would be my best bet, so here I am.

Now, the code for script listener isn't the greatest but I get by. I understand at least what /steps/ I know I take and then marrying those up to the code. Here's the snippet it listened to that I need to run as a script (cleaned in Clean SL":

Code: Select all

// =======================================================
select(false);
function select(makeVisible) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var list = new ActionList();
	var reference = new ActionReference();

	reference.putName( s2t( "layer" ), "About Me" );
	descriptor.putReference( c2t( "null" ), reference );
	descriptor.putBoolean( s2t( "makeVisible" ), makeVisible );
	list.putInteger( 77 );
	descriptor.putList( s2t( "layerID" ), list );
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );
}

// =======================================================
toolModalStateChanged("txBx", "Horizontal Type Tool");
function toolModalStateChanged(ID, title) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();

	descriptor.putInteger( s2t( "level" ), 1 );
	descriptor.putEnumerated( s2t( "state" ), s2t( "state" ), s2t( "enter" ));
	descriptor2.putString( s2t( "ID" ), ID );
	descriptor2.putString( s2t( "title" ), title );
	descriptor.putObject( s2t( "tool" ), s2t( "tool" ), descriptor2 );
	descriptor.putEnumerated( s2t( "kind" ), s2t( "kind" ), s2t( "tool" ));
	descriptor.putBoolean( s2t( "kcanDispatchWhileModal" ), true );
	executeAction( s2t( "toolModalStateChanged" ), descriptor, DialogModes.NO );
}

// =======================================================
select2(false);
function select2(makeVisible) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};

	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var list = new ActionList();
	var reference = new ActionReference();

	reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( c2t( "null" ), reference );
	descriptor.putBoolean( s2t( "makeVisible" ), makeVisible );
	list.putInteger( 77 );
	descriptor.putList( s2t( "layerID" ), list );
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );
}

// =======================================================
toolModalStateChanged2("txBx", "Horizontal Type Tool");
function toolModalStateChanged2(ID, title) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();

	descriptor.putInteger( s2t( "level" ), 0 );
	descriptor.putEnumerated( s2t( "state" ), s2t( "state" ), s2t( "exit" ));
	descriptor2.putString( s2t( "ID" ), ID );
	descriptor2.putString( s2t( "title" ), title );
	descriptor.putObject( s2t( "tool" ), s2t( "tool" ), descriptor2 );
	descriptor.putEnumerated( s2t( "kind" ), s2t( "kind" ), s2t( "tool" ));
	descriptor.putEnumerated( s2t( "reason" ), s2t( "reason" ), s2t( "commit" ));
	descriptor.putBoolean( s2t( "kcanDispatchWhileModal" ), true );
	executeAction( s2t( "toolModalStateChanged" ), descriptor, DialogModes.NO );
}

// =======================================================
set("Youtube");
function set(textKey) {
	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 idT = s2t( "to" );
	var reference = new ActionReference();

	reference.putEnumerated( s2t( "textLayer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
	descriptor.putReference( c2t( "null" ), reference );
	descriptor2.putString( s2t( "textKey" ), textKey );
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

// =======================================================
invokeCommand(-676);
function invokeCommand(commandID) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();

	descriptor.putInteger( s2t( "commandID" ), commandID );
	descriptor.putBoolean( s2t( "kcanDispatchWhileModal" ), true );
	executeAction( s2t( "invokeCommand" ), descriptor, DialogModes.NO );
}

// =======================================================
611736f09c4611e0aa820800200c9a(, "Settings for Image Processor Pro");
function 611736f09c4611e0aa820800200c9a(ImageProcessorProSettings, message) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};

	var descriptor = new ActionDescriptor();

	descriptor.putString( s2t( "ImageProcessorProSettings" ),ImageProcessorProSettings "<ImageProcessorProSettings>
	<input source="currentImage"/>
	<output path="same" subfolder="false" keepStructure="false" retainOriginal="true"/>
	<taskList>
	<task enabled="true" subfolderName="Set 3" colorProfile="Same as Source">
	<saveOptions fileSaveType="psd" psdAlphaChannels="true" psdEmbedColorProfile="true" psdLayers="true" psdMaximizeCompatibility="true" flattenImage="false" psdBPC="16"/>
	<resizeOptions enabled="false"/>
	<action enabled="false" when="After Image Resize" set="Default Actions" name="Vignette (selection)"/>
	<namingOptions startingSerial="1">panel,oneDigit,lowerCaseExtension</namingOptions>
	</task>
	<task enabled="true" subfolderName="Set 4" colorProfile="Same as Source">
	<saveOptions fileSaveType="png" pngInterlaced="false" saveForWeb="false"/>
	<resizeOptions enabled="false"/>
	<action enabled="false" when="After Image Resize" set="Default Actions" name="Vignette (selection)"/>
	<namingOptions startingSerial="1">panel,oneDigit,lowerCaseExtension</namingOptions>
	</task>
	</taskList>
	<preferences>
	<preserveFileName>false</preserveFileName>
	</preferences>
	<uiPrefs>
	<lastX>8</lastX>
	<lastY>212</lastY>
	<lastSettingsFile>C:\Users\HIDDEN\AppData\Roaming\Image Processor Pro PNGnPSD.xml</lastSettingsFile>
	<lastOutputFolder>~/Desktop/Output%20Folder</lastOutputFolder>
	</uiPrefs>
	<date>2020-12-23T14:46:28</date>
	<version>3.2b5</version>
	</ImageProcessorProSettings>" );
	descriptor.putString( s2t( "message" ), message );
	executeAction( s2t( "611736f0-9c46-11e0-aa82-0800200c9a66" ), descriptor, DialogModes.NO );
}
Now... It actually seems to do what I want (because there are no errors) up until line 125. "611736f09c4611e0aa820800200c9a(, "Settings for Image Processor Pro");"

I sadly need to use this plugin because it helps save time on saving my file as a psd AND a png and has a naming feature so that each time I make an "Edit", i can save it as a new version of the last.


Here's what I'm trying to achieve, for context:
Select "X" text layer > "ctrl+enter" to edit text layer > Type "X" text > "ctrl+enter" to confirm edit to text layer > Image Processor Pro (to do its multi save thing that it does). THE END.
Then I would just repeat that over and over so that I'm basically making an image that says "1" and then "2" and then "3", etc. All saved out as their own files like: this_is_image1.png+this_is_image1.psd, this_is_image2.png+this_is_image2.psd, this_is_image3.png+this_is_image3.psd (this is all handled by Image Processor Pro).

SO, here I arrive at my question. What can I do to solve the line 125 issue where it's talking about the error:

Error 25: Expected: ;.
Line 125
-> 611736f09c4611e0aa820800200c9a(, "Settings for Image Processor Pro");

I'd like not to create my own saving part of the script because Image Processor Pro does a much better job, AND i can change its settings before using the script and have it use whatever settings were left/saved in the plugin to begin with. Easy editing.

Apologies that this is very long-winded, i just know what a more broader scope of the issue, i might recieve a better answer, thanks guys.

EDIT: OH, in case people want to see the code before I cleaned it up:

Code: Select all

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc4 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref1.putName( idLyr, "About Me" );
    desc4.putReference( idnull, ref1 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc4.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list1 = new ActionList();
        list1.putInteger( 77 );
    desc4.putList( idLyrI, list1 );
executeAction( idslct, desc4, DialogModes.NO );
// =======================================================
// =======================================================
// =======================================================
// =======================================================
// =======================================================
// =======================================================


// =======================================================
var idtoolModalStateChanged = stringIDToTypeID( "toolModalStateChanged" );
    var desc5 = new ActionDescriptor();
    var idLvl = charIDToTypeID( "Lvl " );
    desc5.putInteger( idLvl, 1 );
    var idStte = charIDToTypeID( "Stte" );
    var idStte = charIDToTypeID( "Stte" );
    var identer = stringIDToTypeID( "enter" );
    desc5.putEnumerated( idStte, idStte, identer );
    var idTool = charIDToTypeID( "Tool" );
        var desc6 = new ActionDescriptor();
        var idIdnt = charIDToTypeID( "Idnt" );
        desc6.putString( idIdnt, """txBx""" );
        var idTtl = charIDToTypeID( "Ttl " );
        desc6.putString( idTtl, """Horizontal Type Tool""" );
    var idTool = charIDToTypeID( "Tool" );
    desc5.putObject( idTool, idTool, desc6 );
    var idKnd = charIDToTypeID( "Knd " );
    var idKnd = charIDToTypeID( "Knd " );
    var idTool = charIDToTypeID( "Tool" );
    desc5.putEnumerated( idKnd, idKnd, idTool );
    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
    desc5.putBoolean( idkcanDispatchWhileModal, true );
executeAction( idtoolModalStateChanged, desc5, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc7 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref2 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref2.putEnumerated( idLyr, idOrdn, idTrgt );
    desc7.putReference( idnull, ref2 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc7.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list2 = new ActionList();
        list2.putInteger( 77 );
    desc7.putList( idLyrI, list2 );
executeAction( idslct, desc7, DialogModes.NO );

// =======================================================
var idtoolModalStateChanged = stringIDToTypeID( "toolModalStateChanged" );
    var desc8 = new ActionDescriptor();
    var idLvl = charIDToTypeID( "Lvl " );
    desc8.putInteger( idLvl, 0 );
    var idStte = charIDToTypeID( "Stte" );
    var idStte = charIDToTypeID( "Stte" );
    var idexit = stringIDToTypeID( "exit" );
    desc8.putEnumerated( idStte, idStte, idexit );
    var idTool = charIDToTypeID( "Tool" );
        var desc9 = new ActionDescriptor();
        var idIdnt = charIDToTypeID( "Idnt" );
        desc9.putString( idIdnt, """txBx""" );
        var idTtl = charIDToTypeID( "Ttl " );
        desc9.putString( idTtl, """Horizontal Type Tool""" );
    var idTool = charIDToTypeID( "Tool" );
    desc8.putObject( idTool, idTool, desc9 );
    var idKnd = charIDToTypeID( "Knd " );
    var idKnd = charIDToTypeID( "Knd " );
    var idTool = charIDToTypeID( "Tool" );
    desc8.putEnumerated( idKnd, idKnd, idTool );
    var idreason = stringIDToTypeID( "reason" );
    var idreason = stringIDToTypeID( "reason" );
    var idcommit = stringIDToTypeID( "commit" );
    desc8.putEnumerated( idreason, idreason, idcommit );
    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
    desc8.putBoolean( idkcanDispatchWhileModal, true );
executeAction( idtoolModalStateChanged, desc8, DialogModes.NO );

// =======================================================
// =======================================================
// =======================================================
// =======================================================
// =======================================================
// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc10 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref3 = new ActionReference();
        var idTxLr = charIDToTypeID( "TxLr" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref3.putEnumerated( idTxLr, idOrdn, idTrgt );
    desc10.putReference( idnull, ref3 );
    var idT = charIDToTypeID( "T   " );
        var desc11 = new ActionDescriptor();
        var idTxt = charIDToTypeID( "Txt " );
        desc11.putString( idTxt, """Youtube""" );
executeAction( idsetd, desc10, DialogModes.NO );

// =======================================================
// =======================================================
// =======================================================
// =======================================================
// =======================================================
// =======================================================


// =======================================================
var idinvokeCommand = stringIDToTypeID( "invokeCommand" );
    var desc27 = new ActionDescriptor();
    var idcommandID = stringIDToTypeID( "commandID" );
    desc27.putInteger( idcommandID, -676 );
    var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );
    desc27.putBoolean( idkcanDispatchWhileModal, true );
executeAction( idinvokeCommand, desc27, DialogModes.NO );

// =======================================================
var idsixoneoneseventhreesixfzeroninecfoursixoneoneezeroaaeighttwozeroeightzerozerotwozerozerocnineasixsix = stringIDToTypeID( "611736f0-9c46-11e0-aa82-0800200c9a66" );
    var desc28 = new ActionDescriptor();
    var idImageProcessorProSettings = stringIDToTypeID( "ImageProcessorProSettings" );
    desc28.putString( idImageProcessorProSettings, """<ImageProcessorProSettings>
  <input source="currentImage"/>
  <output path="same" subfolder="false" keepStructure="false" retainOriginal="true"/>
  <taskList>
    <task enabled="true" subfolderName="Set 3" colorProfile="Same as Source">
      <saveOptions fileSaveType="psd" psdAlphaChannels="true" psdEmbedColorProfile="true" psdLayers="true" psdMaximizeCompatibility="true" flattenImage="false" psdBPC="16"/>
      <resizeOptions enabled="false"/>
      <action enabled="false" when="After Image Resize" set="Default Actions" name="Vignette (selection)"/>
      <namingOptions startingSerial="1">panel,oneDigit,lowerCaseExtension</namingOptions>
    </task>
    <task enabled="true" subfolderName="Set 4" colorProfile="Same as Source">
      <saveOptions fileSaveType="png" pngInterlaced="false" saveForWeb="false"/>
      <resizeOptions enabled="false"/>
      <action enabled="false" when="After Image Resize" set="Default Actions" name="Vignette (selection)"/>
      <namingOptions startingSerial="1">panel,oneDigit,lowerCaseExtension</namingOptions>
    </task>
  </taskList>
  <preferences>
    <preserveFileName>false</preserveFileName>
  </preferences>
  <uiPrefs>
    <lastX>8</lastX>
    <lastY>212</lastY>
    <lastSettingsFile>C:\Users\HIDDEN\AppData\Roaming\Image Processor Pro PNGnPSD.xml</lastSettingsFile>
    <lastOutputFolder>~/Desktop/Output%20Folder</lastOutputFolder>
  </uiPrefs>
  <date>2020-12-23T14:46:28</date>
  <version>3.2b5</version>
</ImageProcessorProSettings>""" );
    var idMsge = charIDToTypeID( "Msge" );
    desc28.putString( idMsge, """Settings for Image Processor Pro""" );
executeAction( idsixoneoneseventhreesixfzeroninecfoursixoneoneezeroaaeighttwozeroeightzerozerotwozerozerocnineasixsix, desc28, DialogModes.NO );

User avatar
Stephen_A_Marsh
Posts: 29
Joined: Sun Aug 04, 2019 12:37 pm

Re: Basic Script Help

Post by Stephen_A_Marsh »

if your action achieves 90% of what you require, then you could simplify things by just scripting only the steps that can't be achieved in the action, then record them into the action. Then run the action via Image Processor Pro.