我是JXA的新手,我正在尝试学习如何在TextEdit中做一些非常基本的事情。我知道如何将文档的段落作为数组:
app = Application('TextEdit')
docPars = app.documents[0].paragraphs()
然后,说,排序。但是我无法弄清楚如何将它作为数组发送回TextEdit(即TE文档中的多个段落)。
TIA
答案 0 :(得分:0)
以下是您的示例
var TextEdit = Application("TextEdit");
var newDocument = TextEdit.Document();
TextEdit.documents.push(newDocument);
for(var i = 0; i < 10; i++){
newDocument.paragraphs.push(TextEdit.Paragraph({ color:"red", size:20 }, "Test line " + i + "\n"))
}
//使用数组更新示例
var TextEdit = Application("TextEdit");
var newDocument = TextEdit.Document();
TextEdit.documents.push(newDocument);
var array = ["test first line", "i love stackoverflow", "i love jxa", "i love apple"]
for(var i = 0; i < array.length; i++){
newDocument.paragraphs.push(TextEdit.Paragraph({ color:"red", size:20 }, array[i] + "\n"))
}