Skip to main content
LaRita
Participant
February 5, 2026
Question

JSX Script Hangs on executeAction for "Define Pattern" with 300DPI JPEGs

  • February 5, 2026
  • 2 replies
  • 61 views

!--startfragment>

I am developing a batch processing script for Photoshop (v25.x). The goal is to take 100 JPEGs (6x6 inches, 300 DPI) and apply them as a Pattern Fill Adjustment Layer inside a nested Smart Object structure (Main PSD > Level 1 SO > Level 2 SO > Pattern Fill Layer).

The Issue:

The script successfully opens the JPEG, flattens it, and performs selection.selectAll(). However, it consistently hangs (Photoshop becomes unresponsive with 'marching ants' visible) when executing the ActionDescriptor for 'setd' (Define Pattern).

What I've Tried:

  • ​Setting app.displayDialogs = DialogModes.NO
  • ​Using app.purge(PurgeTarget.ALLCACHES) between iterations.
  • ​Flattening the source document before defining the pattern.
  • ​Hardcoding the pattern name to avoid naming conflicts.
  • ​Running with GPU Acceleration disabled.

The Question:

Is there a more robust way to define a pattern from an open document that avoids the UI-thread hang, or is there a way to implement a 'Wait/Sleep' state in JSX to allow Photoshop to finish the pattern registration before the script moves to the next executeAction?

Environment: Windows!--endfragment>

    2 replies

    Legend
    February 6, 2026

    There are ways to loop a script and check conditions but it can be a real PITA. UXP might have a better way to handle that. ExtendScript is modal. 

    c.pfaffenbichler
    Community Expert
    Community Expert
    February 6, 2026

    Flattening and Select All should not be necessary with a jpg. 

     

    Please try this function (add the intended name as a string as the argument) – does it malfunction, too? 

    ////// pattern //////
    function createPattern(theName) {
    var desc6 = new ActionDescriptor();
    var ref3 = new ActionReference();
    ref3.putClass( charIDToTypeID('Ptrn') );
    desc6.putReference( charIDToTypeID('null'), ref3 );
    var ref4 = new ActionReference();
    ref4.putProperty( charIDToTypeID('Prpr'), charIDToTypeID('fsel') );
    ref4.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc6.putReference( charIDToTypeID('Usng'), ref4 );
    desc6.putString( charIDToTypeID('Nm '), theName );
    executeAction( charIDToTypeID('Mk '), desc6, DialogModes.NO );
    };