Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Photoshop Scripting line break

I am working on a script for Photoshop where the user can change some text by entering it in the script panel.

By problem is that when the user hits "enter" to create a new line, the output displays a "missing character" glyph instead of a line break.

topRow.add ("statictext", undefined, "Text layer contents:");
var myText = topRow.add ("edittext", undefined, undefined, {name: 'myText', multiline: true});
    myText.characters = 20;
    myText.preferredSize = [150,60];
    myText.active = true;

Any ideas how to resolve this?

like image 806
Craig Jonathan Kristensen Avatar asked Mar 10 '26 22:03

Craig Jonathan Kristensen


1 Answers

It's 2,5 years since you've asked this, but I came across your question by searching for the same problem. And here's how I solved it, hope it helps other people searching for an answer:

Its's working like a charm in PSCC20 if you replace all occurances of possible linebreaks with a default carriage return ("\r"). Here's a working demo script:


w = new Window('dialog {text:"Title"}');

var inputText1 = w.add("edittext", [0,0,250,60], "Text 1", {multiline: true, wantReturn: true}); //multiline, uses return for line breaks instead of CTRL-return

var button = w.add('button {text:"Change"}');
button.onClick = function (){
            dummy = app.activeDocument.artLayers.getByName("Text");
            if(dummy.kind == LayerKind.TEXT){
            theText = inputText1.text.replace( /[\r\n]+/gm, "\r" ); 
            dummy.textItem.contents = theText;  
            w.close();
            }
    }

w.center();
w.show();

PS It seems that "\s+" does not work in ExtendScript, so I'm using "/[\r\n]": What is the meaning of (/^\s+|\s+$/gm) in JavaScript?

like image 162
Corvin Avatar answered Mar 12 '26 12:03

Corvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!