Skip to main content
Participant
December 7, 2018
Answered

Export Alt-Texts + Import Alt-Texts

  • December 7, 2018
  • 1 reply
  • 1046 views

Hello Script Masters, there is this Scripts that allows you to export your Custom Alt Text to a Text File, not sure if its possible to import it back after, incase you needed to make changes to any Alt text.

Orignal

Extract Alt-Texts

AltText-Export.jsx

//DESCRIPTION: This script will export all all text into single txt document on your desktop.

#target indesign

var images = app.activeDocument.allGraphics; // .itemLink.name

var altTextFilePath = "~/Desktop/AltText.txt";

var file = new File(altTextFilePath);

file.open('w');

for(var i=0; i < images.length; i++){

    file.write(  images.itemLink.name + "\n" + images.parent.objectExportOptions.customAltText + "\n\n" );

}

file.close();

alert('You can find "AltText.txt" file on your desktop', "Done");

This topic has been closed for replies.
Correct answer Manan Joshi

Try the following, it will read the same file from Desktop that is produced from your code given above, and add custom alt text to images by finding them with name in the current open document.

#target indesign

var images = app.activeDocument.allGraphics;

var altTextFilePath = "~/Desktop/AltText.txt";

var file = new File(altTextFilePath);

file.open('r')

var altList = {}

var imgName = file.readln()

while(!file.eof)

{

     altList[imgName] = file.readln()

     file.readln()

     imgName = file.readln()

}

for(var i=0; i < images.length; i++)

{

     if(altList[images.itemLink.name] != undefined)

          images.parent.objectExportOptions.customAltText = altList[images.itemLink.name]

}

file.close();

-Manan

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
December 7, 2018

Try the following, it will read the same file from Desktop that is produced from your code given above, and add custom alt text to images by finding them with name in the current open document.

#target indesign

var images = app.activeDocument.allGraphics;

var altTextFilePath = "~/Desktop/AltText.txt";

var file = new File(altTextFilePath);

file.open('r')

var altList = {}

var imgName = file.readln()

while(!file.eof)

{

     altList[imgName] = file.readln()

     file.readln()

     imgName = file.readln()

}

for(var i=0; i < images.length; i++)

{

     if(altList[images.itemLink.name] != undefined)

          images.parent.objectExportOptions.customAltText = altList[images.itemLink.name]

}

file.close();

-Manan

-Manan
Participant
December 7, 2018

   you are God!.

Thank you.