Skip to main content
mariap81355074
Inspiring
November 13, 2019
Answered

Remove suffix of layer name script

  • November 13, 2019
  • 3 replies
  • 1588 views

Hi everyone,

I've tried googling but haven't found what I need; I just need a simple script that will remove the last 4 characters of the active layer name.

Because I use another script to import an image file and it retains the extention .png in the layer name and I just want to remove it, but without changing any other part of the layer name.

 

Thanks so much 🙂

This topic has been closed for replies.
Correct answer Chuck Uebele

Still trying to wrap my head around regex. I still use this method for stripping off an extension:

.split('.')[0];

3 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
November 13, 2019

Still trying to wrap my head around regex. I still use this method for stripping off an extension:

.split('.')[0];

Stephen Marsh
Community Expert
Community Expert
November 13, 2019

If there is a chance that the filename extension may be 2, 3 or 4 (or even 1 or 5+) characters long, then a more robust/bullet-proof option would be:

 

 

.replace(/\.[^\.]+$/, '');

 

 

Legend
November 13, 2019
Deletes a period and the next three characters at the end.
 

 

app.activeDocument.activeLayer.name = app.activeDocument.activeLayer.name.replace(/\....$/, "");

 

mariap81355074
Inspiring
November 13, 2019

Works perfectly, thank you so much 🙂 I really appreciate your help 😄