Skip to main content
Community Expert
Nov 25, 2025 8:07 AM UTC
Answered

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

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?

Eugene TysonCorrect answer
Community Expert
Nov 25, 2025 10:44 AM UTC

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

2 replies

m1b
Community Expert
Community Expert
Nov 25, 2025 8:34 AM UTC

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

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

- Mark 

Translate
Eugene TysonCommunity ExpertAuthorCorrect answer
Community Expert
Nov 25, 2025 10:44 AM UTC

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

Translate