Skip to main content
Participant
June 10, 2021
Answered

Scripting help to insert date in file name

  • June 10, 2021
  • 1 reply
  • 644 views

Using InD 15.1.3, my client likes the date to be part of the file name and he likes it in a specific format: 06.09.21

 

Is there a way to program a shortcut key that will insert the current date in that format when naming/saving a file in InDesign?  I do this 100 times a day.

 

Thank you!

This topic has been closed for replies.
Correct answer Charu Rajput

HI,

Try following snippet to save the file that will append the date in the end.

var dateObj = new Date();
var year = dateObj.getFullYear().toString().substr(-2);
var month = ("0" + (dateObj.getMonth() + 1)).slice(-2);
var date = ("0" + dateObj.getDate()).slice(-2);
var _formattedDate = month + "." + date + "." + year;
var fileName = "Test_" + _formattedDate + ".indd";
var file = app.activeDocument.save(File(Folder.desktop + "/" + fileName));

 

1 reply

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
June 10, 2021

HI,

Try following snippet to save the file that will append the date in the end.

var dateObj = new Date();
var year = dateObj.getFullYear().toString().substr(-2);
var month = ("0" + (dateObj.getMonth() + 1)).slice(-2);
var date = ("0" + dateObj.getDate()).slice(-2);
var _formattedDate = month + "." + date + "." + year;
var fileName = "Test_" + _formattedDate + ".indd";
var file = app.activeDocument.save(File(Folder.desktop + "/" + fileName));

 

Best regards
Participant
September 5, 2023

Hi! I'd like to try this but I don't know where to put the script once I've compiled it in Script Editor so that it is active when I go to save a file. What folder does it belong in?

Robert at ID-Tasker
Legend
September 5, 2023