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

Script to read alt text of XMP description of a linked image

New Here ,
Mar 10, 2017 Mar 10, 2017

Copy link to clipboard

Copied

I have script to display the custom alt text of a image, but I can not get it to read images where the alt text is from XMP description, I have tried all sorts of variations.

(e.g. alt =image.objectExportOptions.properties.DescriptionAltText or alt =image.objectExportOptions.properties.XMPDescriptionAltText)

The script for the "custom" alt text is below.  Can anyone get it to read the XMP description alt text of linked images?

(function(){

  var frames;

  var image;

  var alt;

  frames = app.selection;

  image = frames[0];

  alt =image.objectExportOptions.properties.customAltText

alert("Alt custom text is: " + alt  )

}());

TOPICS
Scripting

Views

854

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
Guru ,
Mar 11, 2017 Mar 11, 2017

Copy link to clipboard

Copied

I'm not sure if I understood your question properly, but maybe like so:

(function(){

    var frames = app.selection,

    image = frames[0],

    link = image.itemLink,

    metadata = link.linkXmp,

    description = metadata.description;

    alert("Description is: '" + description + "'");

}());

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
Contributor ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

// load the XMPScript library

if (ExternalObject.AdobeXMPScript == undefined) {

ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

}

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
Guru ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

Is that any better approach then reading the description property directly from the link's metatada (linkXmp)?

— Kas

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
Guru ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

Well, let's salt the cow to catch the calf.

Here's a working example based on a script I wrote a few years ago (the snippet you copy-pasted from the reference ain't working as it is, at least for me).

Main();

function Main() {

    var doc = app.activeDocument;

    var link = doc.links[0];

    var linkPath = link.filePath;

    var description = GetDescription(linkPath);

    0

}

function GetDescription(linkPath) {

    try {

        if (xmpLib == undefined) {

            var pathToLib = (Folder.fs == "Windows") ? Folder.startup.fsName + "/AdobeXMPScript.dll" : "/Applications/Adobe Bridge CS5.1/Adobe Bridge CS5.1.app/Contents/MacOS/AdobeXMPScript.framework";

            var libfile = new File(pathToLib);

            var xmpLib = new ExternalObject("lib:" + pathToLib);

        }

        var xmpFile = new XMPFile(linkPath, XMPConst.FILE_JPEG, XMPConst.OPEN_FOR_READ);

        var xmp = xmpFile.getXMP();

        var descriptionProperty = xmp.getProperty("http://purl.org/dc/elements/1.1/", "dc:description[1]");

        var description = descriptionProperty.value;

        return description;

    }

    catch(err) {

        $.writeln(err.message + ", line: " + err.line);

    }

}

Here are the files I used for testing the script above.

— Kas

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
New Here ,
Mar 15, 2017 Mar 15, 2017

Copy link to clipboard

Copied

Thank you all, getting closer, but still not working right, might be a very slight issue.

I put the alert at the end : alert("Description is: '" + description + "'");  so I can have a screen readout. It does display the Meta description, but always of the same file regardless of the image that is selected.

Any fixes

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
Guru ,
Mar 16, 2017 Mar 16, 2017

Copy link to clipboard

Copied

LATEST

... but always of the same file regardless of the image that is selected.

The script in my post 4 -- in response to Stefan Rakete  -- was intended to demonstrate how to use XMP object to get description which is a little more complex than getting it directly from the link's metadata. It references the 1st link in the document instead of selection. Another issue with this approach: we have to indicate the image type in the format argument (there are a number of them):

var xmpFile = new XMPFile(linkPath, XMPConst.FILE_JPEG, XMPConst.OPEN_FOR_READ);

Here's my vision of script. I assume that the image is selected with either black, or white arrow.

var scriptName = "Get description from selected link",

doc;

PreCheck();

//===================================== FUNCTIONS ======================================

function Main(image) {

    var link = image.itemLink,

    metadata = link.linkXmp, 

    description = metadata.description; 

    alert("Description is: '" + description + "'", scriptName, false);

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function PreCheck() {

    var image;

    if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);

    doc = app.activeDocument;

    if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);

    if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);

    if (app.selection.length == 0 || app.selection.length > 1) ErrorExit("One image should be selected.", true);

   

    if (app.selection[0].constructor.name == "Image") { // image selected with white arrow

        image = app.selection[0];

    }

    else if (app.selection[0].images.length > 0) { // container selected with black arrow

        image = app.selection[0].images[0];

    }

    else {

        ErrorExit("No image in the selection.", true);

    }

    Main(image);

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

function ErrorExit(error, icon) {

    alert(error, scriptName, icon);

    exit();

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

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