Skip to main content
Retsied
Known Participant
December 15, 2019
Question

Add additional space to string at every existing space

  • December 15, 2019
  • 4 replies
  • 1362 views

Hello, I'm trying to make a script that edits a layer's text by adding another space at every instance there is already an existing space. 

"Edit spaces" to

"Edit  spaces"

Any help much appreciated. Thanks in advance!

This topic has been closed for replies.

4 replies

rob day
Community Expert
Community Expert
December 15, 2019

 

"Edit spaces" to

"Edit spaces"

 

It sounds like you are trying to get more word spacing? If that's the case it would be easier to manipulate the word spacing via the Paragraph Style.

 

So the default Word Spacing is 80 |100 |133

 

 

 

You can increase the Word Spacing and keep the same Letter Spacing:

 

Chuck Uebele
Community Expert
Community Expert
December 15, 2019

Try this:

var textI = app.activeDocument.activeLayer.textItem
textI.contents = textI.contents.replace(/ /g,"  ");
Retsied
RetsiedAuthor
Known Participant
December 24, 2019

Hmm, this is seemingly exactly what I want, however, doesn't seem to be working for me. Did this actually work for you? Something that's interesting is I copy/pasted the below code from my file, and the number of spaces between the " " pasted as only one, despite in the code having several. Curious..

 

var myText = doc.activeLayer.textItem
myText = myText.contents.replace(/ /g," ");

 

 

Chuck Uebele
Community Expert
Community Expert
December 24, 2019

You only have one space between the quotes, you need two. What you are doing is replacing a single space with another single space.

JJMack
Community Expert
Community Expert
December 15, 2019

You can use Google search to search for scripts poster on this site for editing text layers.  Some have been posted. This site search is useless for searching for things like that. Use Google.

JJMack
lambiloon
Community Expert
Community Expert
December 15, 2019

Hi it can be done with Actions you need to record it...Regards

Ali Sajjad / Graphic Design Trainer / Freelancer / Adobe Certified Professional
JJMack
Community Expert
Community Expert
December 15, 2019

How can it be done with an action.  Actions can not use logic to retrieve text layers and search for spaces and insert additional spaces.  And if  you double the amount of spaces how would an action known if the revised text will fit on canvas.  How would an action know how many text layer there are  or where in the layer stack text layers are.  A Photoshop script may be able to do what they want to do. It would not be easy to program such a Photoshop script. If it is not something  they would use all the time they would save time manually editing their text layers.

JJMack
Legend
December 16, 2019

in action it colud be done throw find&replace menu of text item