首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Adobe InDesign脚本更改为大写并将文本复制到剪贴板

Adobe InDesign脚本更改为大写并将文本复制到剪贴板
EN

Stack Overflow用户
提问于 2017-08-21 19:59:28
回答 1查看 1.3K关注 0票数 0

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

代码语言:javascript
复制
#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");
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-21 22:17:58

代码语言:javascript
复制
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");
}

这里它使用的是选定的对象:

代码语言:javascript
复制
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");
}

正在复制到剪贴板:

代码语言:javascript
复制
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");
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45796565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档