Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Remove suffix of layer name script

Explorer ,
Nov 13, 2019 Nov 13, 2019

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 🙂

TOPICS
Actions and scripting
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

People's Champ , Nov 13, 2019 Nov 13, 2019
Deletes a period and the next three characters at the end.
 

 

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

 

Translate
Community Expert , Nov 13, 2019 Nov 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(/\.[^\.]+$/, '');

 

 

Translate
Community Expert , Nov 13, 2019 Nov 13, 2019

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

.split('.')[0];

Translate
Adobe
People's Champ ,
Nov 13, 2019 Nov 13, 2019
Deletes a period and the next three characters at the end.
 

 

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2019 Nov 13, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2019 Nov 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(/\.[^\.]+$/, '');

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2019 Nov 13, 2019
LATEST

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

.split('.')[0];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines