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

remove a part of the writing

Enthusiast ,
Apr 04, 2025 Apr 04, 2025

Saving uxp file

remove part of save name

from so

_DSC0193a.jpg_3.jpg

to so

_DSC0193a_3.jpg

TOPICS
Actions and scripting
156
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 1 Correct answer

Community Expert , Apr 05, 2025 Apr 05, 2025

@Ciccillotto 

 

Without your sample code I can't give the following any context, as saving files in UXP isn't as simple as with ExtendScript.

 

In ExtendScript, you can use a regular expression in a variable such as:

 

var fileName = app.activeDocument.name.replace(/^(.*)\.jpg(_.*\.jpg)$/, '$1$2');

 

It's probably the same or very similar with UXP DOM, you would likely just change the var for let etc.

 

EDIT:

 

The following UXP code works:

 

const photoshop = require("photoshop");
const core = 
...
Translate
Adobe
Community Expert ,
Apr 05, 2025 Apr 05, 2025

Do you mean you want to batch rename files?
Not sure if that's what you are asking but you can do that with Adobe Bridge (it comes with Photoshop)

Imaginerie_0-1743843349880.png

what it will come up with

Imaginerie_1-1743843485463.png

 

It will apply to all the files you selected.

https://helpx.adobe.com/uk/bridge/using/automate-tasks-adobe-bridge.html

Let me know if that's what you meant!

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 ,
Apr 05, 2025 Apr 05, 2025

@Ciccillotto 

 

Without your sample code I can't give the following any context, as saving files in UXP isn't as simple as with ExtendScript.

 

In ExtendScript, you can use a regular expression in a variable such as:

 

var fileName = app.activeDocument.name.replace(/^(.*)\.jpg(_.*\.jpg)$/, '$1$2');

 

It's probably the same or very similar with UXP DOM, you would likely just change the var for let etc.

 

EDIT:

 

The following UXP code works:

 

const photoshop = require("photoshop");
const core = photoshop.core;
let fileName = app.activeDocument.name.replace(/^(.*)\.jpg(_.*\.jpg)$/, '$1$2');
core.showAlert(fileName);

 

regex.png

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
Enthusiast ,
Apr 05, 2025 Apr 05, 2025

Stefano thanks I looked for other ways and it seems that I solved it.

I will put your answer as correct.

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 ,
Apr 05, 2025 Apr 05, 2025
LATEST

@Ciccillotto 

 

You're welcome!

 

I learnt regex before scripting, so it's more natural for me to use. Others who learn scripting first are more comfortable with basic JavaScript string manipulation using .split or other methods:

const photoshop = require("photoshop");
const core = photoshop.core;
let fileName = app.activeDocument.name;
let parts = fileName.split('.jpg');
fileName = parts[0] + (parts[1] || '');
core.showAlert(fileName);

 

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