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

Script to copy clipboard contents into Object Export Options of selected image?

Contributor ,
Dec 31, 2021 Dec 31, 2021

I'm trying to find a script that will automate an alt text process.

Once I've selected the Image I'm wanting to affect, access an items 'Object Export Options',  change the Alt Text Source to 'Custom' and then insert clipboard contents (text i've copied) in the window.

I know its just eliminating a couple clicks, but If i can just copy text and select an image and then click the script when i'm going through mulitple photos in a document, that would be cool.

Is this possible?

Screen Shot 2021-12-31 at 9.46.54 AM.png

TOPICS
How to , Scripting
1.2K
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

Advisor , Dec 31, 2021 Dec 31, 2021

Hello @LynxKx,

 

Give the below script a try, I know the code could be refined a bit more but it does what you're looking for...

 

 
 function Main() {

  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'+  
  
...
Translate
Community Expert , Jan 01, 2022 Jan 01, 2022

Hi @LynxKx , Could you skip getting the clipboard contents, and run the script with the text frame and image selected? Something like this gets the text from the text frame:

 

var s = app.documents.item(0).selection;
var t, obj;
for (var i = 0; i < s.length; i++){
    if (s[i].constructor.name == "TextFrame") {
        t=s[i].contents;
    } else {
        obj=s[i]
    }
};   


if (t != undefined && s.length ==2) {
    try { var objectExportOptions = obj.objectExportOptions;
        with (objec
...
Translate
Community Expert ,
Dec 31, 2021 Dec 31, 2021

I don't believe Alt Text is available to the scripting DOM, unfortunately.

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
Advisor ,
Dec 31, 2021 Dec 31, 2021

Hello @LynxKx,

 

Give the below script a try, I know the code could be refined a bit more but it does what you're looking for...

 

 
 function Main() {

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

myCustomAltText = GetClipboard();

	try { var objectExportOptions = mySelObject.objectExportOptions;
	  with (objectExportOptions) {
     altTextSourceType = SourceType.SOURCE_CUSTOM;
     customAltText = myCustomAltText;
		}} catch(e) {}
}
  
 if (app.selection.length == 0) {
		 alert("Error!\nNothing is selected.");
	}

  else if (app.selection.length > 1) {
    alert("Error!\nThere's more than one object selected.");
  }

  else if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline")) {
		alert("Error!\nSome text is selected.");
	}

  mySelObject = app.selection[0];
  Main();	

 

Regards,

Mike

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
Contributor ,
Jan 03, 2022 Jan 03, 2022

Totally works! and will be so helpful when I have repeat graphics with the same alt text! Thank you so much for your help! 

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
Contributor ,
Jan 06, 2022 Jan 06, 2022
LATEST

Is there a way to do this for form fields description as well? Copy clipboards contents and use the javascript to put in the selected form field description? or 

Screen Shot 2022-01-06 at 1.55.38 PM.png

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 ,
Dec 31, 2021 Dec 31, 2021

Listen to Mike, not me. Alt Text isn't available to the DOM for hyperlink objects. That's where I was getting confused. 

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 ,
Jan 01, 2022 Jan 01, 2022

Hi @LynxKx , Could you skip getting the clipboard contents, and run the script with the text frame and image selected? Something like this gets the text from the text frame:

 

var s = app.documents.item(0).selection;
var t, obj;
for (var i = 0; i < s.length; i++){
    if (s[i].constructor.name == "TextFrame") {
        t=s[i].contents;
    } else {
        obj=s[i]
    }
};   


if (t != undefined && s.length ==2) {
    try { var objectExportOptions = obj.objectExportOptions;
        with (objectExportOptions) {
            altTextSourceType = SourceType.SOURCE_CUSTOM;
            customAltText = t;
        }
    } catch(e) {}
} else {
    alert("Select a text frame and object")
}

 

 

Screen Shot 5.png

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
Contributor ,
Jan 01, 2022 Jan 01, 2022

That would actually be perfect!! I'm anxious to get to my computer and try it out! Will let you know! Thank you SO MUCH!!

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
Contributor ,
Jan 01, 2022 Jan 01, 2022

That worked so beautifully! thank you so much! will save me so much time!

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