Copy link to clipboard
Copied
Is there a script to be able to remove extra spaces (and soft returns) within a text block in photoshop?
And if so, how would I load the script again? I remember there's a folders somewhere I need to put the script file into? Then it shows up under the fle menu, under automations, right.
@NDL_DH – Yes, as I previously wrote I don't know why the formatting is lost or how to avoid that. More accomplished scripters may be able to answer.
You can use the Edit > Find and Replace Text command. ScriptingListener can also capture the use of this as well and it doesn't remove the formatting in my simple tests.
The issue is that it uses strings as input/output, I can't work out how to "inject" variables or regular expressions. Therefore it would need repetition with hard-coded values:
...Copy link to clipboard
Copied
This is amazing.
Thanks so much, I just modified it by changing "true" to "false" in the 1st column (of the true/false section), to designate unchecking the "search all layers" option.
And from what I can see, I can add more lines (right?), to include spaces immediately followed by line break (soft and hard returns, etc).
But I'll have to work on that tomorrow.
Thanks so much man, huge help. Definitely a massive breakthrough.
findReplaceText(" ", " ", false, false, false, false, false); // 2 spaces
findReplaceText(" ", " ", false, false, false, false, false); // 3 spaces
findReplaceText(" ", " ", false, false, false, false, false); // 4 spaces
findReplaceText(" ", " ", false, false, false, false, false); // 5 spaces
function findReplaceText(find, replace, checkAll, forward, caseSensitive, wholeWord, ignoreAccents) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putProperty( s2t( "property" ), s2t( "replace" ));
reference.putEnumerated( s2t( "textLayer" ), s2t( "ordinal" ), s2t( "allEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor2.putString( s2t( "find" ), find );
descriptor2.putString( s2t( "replace" ), replace );
descriptor2.putBoolean( s2t( "checkAll" ), checkAll );
descriptor2.putBoolean( s2t( "forward" ), forward );
descriptor2.putBoolean( s2t( "caseSensitive" ), caseSensitive );
descriptor2.putBoolean( s2t( "wholeWord" ), wholeWord );
descriptor2.putBoolean( s2t( "ignoreAccents" ), ignoreAccents );
descriptor.putObject( s2t( "using" ), s2t( "findReplace" ), descriptor2 );
executeAction( s2t( "replace" ), descriptor, DialogModes.NO );
}
Copy link to clipboard
Copied
@NDL_DH wrote:
This is amazing.
Thanks so much, I just modified it by changing "true" to "false" in the 1st column (of the true/false section), to designate unchecking the "search all layers" option.
That is correct, to illustrate:
And from what I can see, I can add more lines (right?), to include spaces immediately followed by line break (soft and hard returns, etc).
As I wrote previously, I can't find a way to access hard or soft line breaks, but if you work it out let me know!
Copy link to clipboard
Copied
Oh, I see.
Initially I assumed you meant that with jsx purely, finding and changing linebreaks were not possible.
But even with this more manual of sorts, method, it's still not possible. Okay.
Will have to download ScriptingListener and play with it.
That's how you've been making these scripts?
Copy link to clipboard
Copied
@NDL_DH wrote:
Will have to download ScriptingListener and play with it.
That's how you've been making these scripts?
The first scripts that I posted were pure hand-keyed (D?)OM code, straight out of the JavaScript reference.
Yes, this latest script is generated by modified ScriptingListener code, however, the raw SL code has been put into a function with the parameters placed into the function call. This allows the use of multiple "calls" to the single main function block, reducing the repetition of the main code block recorded by ScriptingListener.
Although one can manually create a function from the raw recording, it is useful to run the code through the Clean SL script to reduce the code length and make the Action Manager (AM) code slightly more legible.
https://community.adobe.com/t5/photoshop-ecosystem-discussions/clean-sl/m-p/9358507/page/6
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more