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

Renaming files

Explorer ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

Hello everybody,

 

Regarding a jsx file

1. For an export from Indesign to JPEG, how to name JPEG files with a specific name wich is the 13 first characters (EAN) among the 14 first of every Indesign files name :

9782340-046337_COUV_2022_02_24.indd

becomes

9782340046337.jpg

 

2. And then save the export file on the desktop without changing the path on every machine

 

Thanks a lot for your help

 

TOPICS
Scripting

Views

210

Translate

Translate

Report

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

Guide , Nov 04, 2024 Nov 04, 2024
doc.name.substring(0,14).replace("-","") + ".jpg"
 
(^/)  The Jedi

Votes

Translate

Translate
Community Expert ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

You meant the first 14 characters, correct? Not the first 13.

 

 

jpgName = app.activeDocument.name.replace (/(.{14}).+/, '$1.jpg');

 

or perhaps

 

 jpgName = app.activeDocument.name.replace (/^([-\d]+).+/, '$1.jpg')

 

which amounts to 'all digits and dashes from the start of the string', so you needn't worry about how many characters you want to catch.

 

> And then save the export file on the desktop without changing the path on every machine

 

What exactly do you mean by 'witout changing the path'? The desktop is its own path.

Votes

Translate

Translate

Report

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 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

Hello Peter,

thanks for your quick answer.

For the moment I have that :

//export the JPEG
doc.exportFile(
ExportFormat.jpg,
File("/Users/Smith/Desktop/" + doc.name.substring(0,13) + ".jpg"),
 
Wich gives :
9782340-04633.jpg
from
9782340-046337_COUV_2022_02_24.indd
 
My goal is to have 9782340046337.jpg
 
And if possible, instead of /Users/Smith/Desktop/, a generic way to save the file in the desktop wathever the computer is to.

Votes

Translate

Translate

Report

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 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

You need .substring(0,14) to get the file name correct.

 

The path on any computer's desktop is ~/Desktop/, so you would use

File("~/Desktop/" + doc.name.substring(0,14) + ".jpg"),

 

 

Votes

Translate

Translate

Report

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 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

OK thanks.

So I have 9782340-046337.jpg on the desktop, but what I want is 9782340046337.jpg, 13 digits without the dash…

🙂

Votes

Translate

Translate

Report

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
Guide ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

LATEST
doc.name.substring(0,14).replace("-","") + ".jpg"
 
(^/)  The Jedi

Votes

Translate

Translate

Report

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