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

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

Community Expert ,
Nov 25, 2025 Nov 25, 2025

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?

TOPICS
Scripting
93
Translate
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 2 Correct answers

Community Expert , Nov 25, 2025 Nov 25, 2025

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

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

- Mark 

Translate
Community Expert , Nov 25, 2025 Nov 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");

Translate
Community Expert ,
Nov 25, 2025 Nov 25, 2025

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

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

- Mark 

Translate
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 25, 2025 Nov 25, 2025
LATEST

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
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