Skip to main content
Legend
March 21, 2025
Question

Setting text contents via script changes formatting

  • March 21, 2025
  • 1 reply
  • 383 views

Setting textItem contents for an empty text layer via script changes the text layer formatting. Verified on both Windows 10 Pro and Mac Sequoia, Photoshop 26.4.1.

 

1. Create a new document.

2. Add a type layer with the text tool, type in a few characters

3. Manually set font and size formatting

4. Manually select and delete the text, clicking the checkmark in the Options bar to leave a blank type layer

5. Run the following code snippet:

var docRef = app.activeDocument;
var layerRef = docRef.activeLayer;
var textRef = layerRef.textItem;
textRef.contents = Window.prompt('Enter text');

Result: The text size and font will change to Myriad Pro 9 point. This is regardless of the setting in Preferences/Settings->Type->Set default font size automatically

Expected: Size and font will remain the same

Double-clicking the type layer in the Layers panel and then manually typing in characters retains the previous formatting

1 reply

c.pfaffenbichler
Community Expert
Community Expert
May 25, 2025
quote

clicking the checkmark in the Options bar to leave a blank type layer

Say what? 

 

Anyway, I can reproduce the issue. 

Maybe you should check whether AM or UXP code behave the same as the DOM code. 

 

I wonder why you want a completely empty Type Layer, though?

What would be the problem with leaving placeholder text or at least a space?

(Which is not to say that the behaviour does not seem unexpected and undesirable.) 

ExUSAAuthor
Legend
June 2, 2025

I have a script which creates a new, empty, formatted text layer that I can add text to. I use it constantly for product photos with text overlays.

c.pfaffenbichler
Community Expert
Community Expert
June 2, 2025

So set the intended type properties via the Script.