【问题标题】:Adobe InDesign script change to uppercase and copy text to clipboardAdobe InDesign 脚本更改为大写并将文本复制到剪贴板
【发布时间】:2017-08-21 11:59:28
【问题描述】:

我正在尝试创建一个 Adob​​e InDesign 脚本,该脚本将选择文本,将所选文本更改为大写,然后复制相同的文本。 我被卡住了。

#target "InDesign"

var myDoc = app.activeDocument;


if(app.documents.length != 0){
    if(app.selection.length == 1){
        try{           
            //var text = app.selection[0].
            var frame1 = page.textFrames[0];
            //var frame2 = page.textFrames[1];

            frame1.texts.everyItem().select();
            //frame1.
            app.copy();
         }
        catch(e){
            alert ("Please select text", "Selection");
        }
    }
 else{
    alert ("Please select text", "Selection");
  }  
}
else{
    alert("Something wrong");
}

【问题讨论】:

  • 获取错误catch(e){ alert ("Exception happened: " + e, "Exception"); 以帮助您解决所发生的问题。我在var frame1 = page.textFrames[0]; 中得到“页面未定义”

标签: adobe-indesign extendscript


【解决方案1】:
var myDoc = app.activeDocument;

if(app.documents.length != 0){
    if(app.selection.length == 1){
        try{           
            //var text = app.selection[0].
            //var frame1 = app.selection[0].textBoxes[0].contents;
            var frame1 = app.documents[0].pages[0].textFrames[0];
            frame1.contents = frame1.contents.toUpperCase();
         }
        catch(e){
            alert ("Exception : " + e, "Exception");
        }
    }
 else{
    alert ("Please select text", "Selection");
  }  
}
else{
    alert("Something wrong");
}

这里是使用选中的对象:

var myDoc = app.activeDocument;

if(app.documents.length != 0){
    if(app.selection.length == 1){
        try{           
            var frame1 = app.selection[0];
            frame1.contents = frame1.contents.toUpperCase();
         }
        catch(e){
            alert ("Exception : " + e, "Exception");
        }
    }
 else{
    alert ("Please select text", "Selection");
  }  
}
else{
    alert("Something wrong");
}

复制到剪贴板:

var myDoc = app.activeDocument;

if(app.documents.length != 0){
    if(app.selection.length == 1){
        try{           
            var selectedStuff = app.selection[0];

            //upperCase the selection right away.
            //If a textFrame is selected, everything in the TextFrame gets upperCased.
            //If only part of the text is selected, then only part of the text is upperCased.
            selectedStuff.contents = selectedStuff.contents.toUpperCase();
            ///////////////

            //app.copy(copies the selected Item, not only Text) so find out what's is selected before you shove it onto the clipboard.
            if(selectedStuff instanceof TextFrame){
                //The selected item was a textFrame, a TextFrame can't be pasted into Notepad, so lets select all the text in that frame instead.
                app.selection = selectedStuff.texts;
                }
            //Now copy the selection. At this point, only TEXT should be selected, so pasting should always work.
            app.copy();
         }
        catch(e){
            alert ("Exception : " + e, "Exception");
        }
    }
 else{
    alert ("Please select text", "Selection");
  }  
}
else{
    alert("Something wrong");
}

【讨论】:

  • 好的,您介意添加代码以将内容复制到剪贴板吗?
  • app.copy() 将copy 选中的item 复制到剪贴板。如果 item 是文本框,则将 textFrame 复制到剪贴板(此 item 类型只有 Indesign 知道,因此只能粘贴回 inDesign)。如果选定的 item 是 textFrame 中的文本,则将文本复制到剪贴板。因为一串文本只是一串文本,几乎每个运行的程序都知道 item type,因此,您选择/复制的项目几乎可以粘贴回任何东西。稍后我会添加一些代码。
  • @KamosKamotho,添加了剪贴板功能
猜你喜欢
  • 2012-06-19
  • 2021-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多