Skip to main content
Legend
Mar 21, 2025 1:56 PM UTC
Question

Setting text contents via script changes formatting

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

6 replies

c.pfaffenbichler
Community Expert
Community Expert
May 25, 2025 3:25 PM UTC
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.) 

Translate
ExUSAAuthor
Legend
Jun 2, 2025 1:44 PM UTC

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.

Translate
c.pfaffenbichler
Community Expert
Community Expert
Jun 2, 2025 5:25 PM UTC

So set the intended type properties via the Script. 

Translate