• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Apply Custom alt text in inDesign via scripts

Explorer ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Hi Community Expert,

Currently, I'm working on one project in that I want to give custom alt text to 100+ images mentioned in the caption.

NewInScript_0-1664860453586.png

My current process is we copy the caption then right-click on the image and select "Object Export Options"  select "Alt Text" -- Custom and paste.


NewInScript_1-1664860829598.png

Can someone help me with that how we can create a script for this?

 

Thanks in advance!!

TOPICS
EPUB , Scripting

Views

1.1K

Translate

Translate

Report

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 1 Correct answer

Community Expert , Oct 04, 2022 Oct 04, 2022

No need to select anything, Mike. Look for anchored images, a return, and the following character (i.e. an inline image and the following paragraph). If the  image is in an 'IMG - Figure' paragraph and the following paragraph is an 'IMG - Caption', then set the inline's alt text to the caption's content:

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '~a\\r.';
found = app.documents[0].findGrep();

for (i = 0; i < found.length; i++) {
  if (found[i].paragraphs[0].appliedPara
...

Votes

Translate

Translate
Community Expert ,
Oct 03, 2022 Oct 03, 2022

Copy link to clipboard

Copied

Hi @Shanpub, I think this can be done fairly easily so long as there is a reliable way to find the caption of the selected image. How is the caption built? Is it a Live Caption? Is it in a particular paragraph style? Can you share a one or two page indesign file with example image and captions please.

- Mark

Votes

Translate

Translate

Report

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
Explorer ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

@m1b caption is not a Live Caption it's a static caption change for every image.

Yes, we use the "Image - Caption"  Paragraph style. Please find attached the InDesign file.

Votes

Translate

Translate

Report

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
Advisor ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

Hello @Shanpub,

 

Give the below script a try and let us know if that's what you were looking for...

function GetClipboard(){  
    var clipboard;  
    if(File.fs == "Macintosh"){  
        var script = 'tell application "Finder"\nset clip to the clipboard\nend tell\nreturn clip';  
        clipboard = app.doScript (script,ScriptLanguage.APPLESCRIPT_LANGUAGE);  
    } else {  
        var script = 'Set objHTML = CreateObject("htmlfile")\r'+  
        'returnValue = objHTML.ParentWindow.ClipboardData.GetData("text")';  
        clipboard = app.doScript(script,ScriptLanguage.VISUAL_BASIC);  
    }  
    return clipboard;  
} 

myClipboardContents = GetClipboard();

var mySelection = app.selection[0];

if (app.selection.length == 0) {
    alert ("Nothing is selected.");
} 

else if (mySelection.graphics.length == 1) {
 mySelection.objectExportOptions.altTextSourceType = SourceType.SOURCE_CUSTOM;
 mySelection.objectExportOptions.customAltText = myClipboardContents;
} else {
alert('Error!\n The selection is not an image.');
}

Regards,

Mike

Votes

Translate

Translate

Report

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 ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

Hi together,

FWIW: Alt Text still is not part of the InDesign ExtendScript scripting DOM ( Document Object Model ).

Another one: Alt Text will be removed if you export to IDML and open the IDML file as InDesign document.

( Just a warning; you'll find a bug report about this at InDesign UserVoice. )

 

EDITED: Seems, that I had this wrongā€¦

 

Regards,
Uwe Laubender

( Adobe Community Expert )

Votes

Translate

Translate

Report

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 ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

No need to select anything, Mike. Look for anchored images, a return, and the following character (i.e. an inline image and the following paragraph). If the  image is in an 'IMG - Figure' paragraph and the following paragraph is an 'IMG - Caption', then set the inline's alt text to the caption's content:

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '~a\\r.';
found = app.documents[0].findGrep();

for (i = 0; i < found.length; i++) {
  if (found[i].paragraphs[0].appliedParagraphStyle.name !== 'IMG - Figure' 
    || found[i].paragraphs[1].appliedParagraphStyle.name !== 'IMG - Caption' ) {
    continue;
  }
  found[i].paragraphs[0].allGraphics[0].parent.objectExportOptions.properties = {
    altTextSourceType: SourceType.SOURCE_CUSTOM,
    customAltText: found[i].paragraphs[1].contents.replace('\r',''),
  }
}

 

Peter

Votes

Translate

Translate

Report

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
Explorer ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

Thanks

Votes

Translate

Translate

Report

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
Explorer ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

Thanks a lot!! @Peter Kahrel this script is spot on

Votes

Translate

Translate

Report

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 ,
Oct 31, 2022 Oct 31, 2022

Copy link to clipboard

Copied

LATEST

Apologies for not catching this earlier.

A graphic's Alt Text and caption should never be the same.

Reasons:

  • Alt Text literally describes what can be visually seen in the graphic. It can't editorialize or expand on that visual information.
  • Captions can say anything about the graphic or subject, can editorialize, and can contain other related information.
  • Those who use assistive technologies will be forced to hear both the Alt Text and the caption. When they both have the same content, then it's redundent and violates the accessibility standards. And you'll confuse the heck of those using screen readers because they won't know why they're hearing the "alt text" twice. Did they do something wrong? Is there something wrong with their screen reader?

 

 

 

|    Bevi Chagnon   |  Designer, Trainer, & Technologist for Accessible Documents |
|    PubCom |    Classes & Books for Accessible InDesign, PDFs & MS Office |

Votes

Translate

Translate

Report

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