Skip to main content
Known Participant
November 4, 2024
Answered

Renaming files

  • November 4, 2024
  • 1 reply
  • 488 views

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

 

This topic has been closed for replies.
Correct answer FRIdNGE

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"),

 

 


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

1 reply

Peter Kahrel
Community Expert
Community Expert
November 4, 2024

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.

Known Participant
November 4, 2024

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.
Peter Kahrel
Community Expert
Community Expert
November 4, 2024

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"),