Skip to main content
Community Expert
November 25, 2025
Answered

Script: write to text file but use InDesign Filename in the output?

  • November 25, 2025
  • 1 reply
  • 184 views

I have a script ready that pushes a report to the folder as a text file. 

 

But want it to use the InDesign document name in the dialog - at the moment it shows Untitled.

 

It's not critical, but how do I get the filename into the output file automatically? 

 

Any ideas?

Correct answer Eugene Tyson

Ah thanks - I think I figured it out

 

var doc = app.activeDocument;

// get filename without extension
var baseName = doc.name.replace(/\.[^\.]+$/, "");

// suggest this as the default in the Save dialog
var reportFile = File.saveDialog("Save report as", baseName + ".txt");

1 reply

m1b
Community Expert
Community Expert
November 25, 2025

Hi @Eugene Tyson I strongly suspect I am misunderstanding your request, but otherwise...

var doc = app.activeDocument;
alert(doc.name.replace(/\.[^\.]+$/, ''));

- Mark 

Eugene TysonCommunity ExpertAuthorCorrect answer
Community Expert
November 25, 2025

Ah thanks - I think I figured it out

 

var doc = app.activeDocument;

// get filename without extension
var baseName = doc.name.replace(/\.[^\.]+$/, "");

// suggest this as the default in the Save dialog
var reportFile = File.saveDialog("Save report as", baseName + ".txt");