Skip to main content
Known Participant
January 17, 2024
Answered

Photoshop Actions - Add File Name

  • January 17, 2024
  • 2 replies
  • 734 views

Hello All

 

I am hoping that one of you that is more technically adept than myself can answer my question - if so I would be very grateful.

 

I am trying to add the file name as a text layer to a .jpg file.

 

I have downloaded a script (Add File Name.jsx) which does this perfectly.

 

However, I want to remove the .jpg extension, which I have done via an action that I recorded that first runs the above script then edits the text layer to remove the .jpg.

 

This works well the first time, but on subsequent runs, it simply uses the file name that was used when I first recorded the action.

 

I am sure that there is an easy way to achieve this, but I am not competent enough to work out how to access the text layer cretaed by the script rather than when I recorded it.

 

I would be very grateful for any help in this.

 

Thank you in advance

Fred

This topic has been closed for replies.
Correct answer Stephen Marsh

You can use the forum software toolbar icon </> to post code. The code below uses a regular expression to remove the filename extension:

 

#target photoshop
try {
    app.activeDocument.activeLayer.textItem.contents = app.activeDocument.name.replace(/\.[^\.]+$/, '');
} catch (e) {}

 

 

 

2 replies

Stephen Marsh
Community Expert
Community Expert
January 17, 2024

@Fred Barrington 


Please post the script code so that it can be modified.

 

Otherwise, try using text find/replace in the action to remove .jpg rather than editing the actual text layer directly.

Known Participant
January 18, 2024

thank you - I tried attach the script and action, but the file types are not supported. so I am pasting here if that is OK.

Script:

#target photoshop

try{app.activeDocument.activeLayer.textItem.contents = app.activeDocument.name}

catch(e){}

------------

Action: I attach a screenprint as notepad seemed incomprehensible!

BTW

I reralise that jpgs do not save layers, but the action creates the text layer, and the problem is before I save it.

Known Participant
January 18, 2024

Sorry - I had not realised find/replace works in text layers. I jhave tried this and it works well..

 

Thank you for the suggestion - it is much appreciated.

jane-e
Community Expert
Community Expert
January 17, 2024
quote

I am trying to add the file name as a text layer to a .jpg file.

By @Fred Barrington

 

JPEGs do not support layers. When you save the JPEG, does it revert to one Background layer called "Background" and remove your filename altogether?

 

Jane