javascript - 从主题演讲中提取PresentationNotes

标签 javascript applescript osx-yosemite automator javascript-automation

我很难使用 JXA(osx 的 Javascript)从主题演讲中提取演示笔记,我不想使用 applescript。该脚本的功能远不止提取注释。

看起来很简单。然而,当我得到presentationNotes时,它位于一个RichText对象中,该对象似乎无论如何都无法获取普通文本。 所以我想我应该打开文本编辑器并将它们写入其中。 好吧,我不知道该怎么做。

var app = Application('Keynote')
document = app.documents[0] 
slide_name = document.name()
i = 1 // loop through folder contents
folder_name = 'chapter'+i
//create a folder
var textEdit = Application('textEdit')
textEdit.activate()
var doc = textEdit.make({new:'document'})
doc.text = "fsdfsdfs"
var c = 0;
for(slide in document.slides){

    var s = document.slides[slide]
    var note = s.presentationNotes // returns object specifier

    //textEdit.documents[0].push(note)
    // I've tried lots of things here.


}

任何想法或帮助将不胜感激。我看过一些 applescript 示例,但是我无法翻译它们。显然,applescript 作为文本与 toString() 无关

最佳答案

你就快到了。您不应该推送文本,而应该推送文本的段落对象。

这是一个完整的示例(仅限文本)。 它使用当前打开的 Keynote 和 TextEdit 文档。

var Keynote = Application("Keynote");
var presentation = Keynote.documents[0];

var TextEdit = Application("TextEdit");
var document = TextEdit.documents[0];

document.paragraphs.push( TextEdit.Paragraph({color:"red", size:18}, "presentation: "+ presentation.name()+"\n" ))

for (var i=0; i<presentation.slides.length; i++) {
    slide = presentation.slides[i];
    slideTitle = slide.defaultTitleItem().objectText();
    notes = slide.presenterNotes(); // text only

    document.paragraphs.push( TextEdit.Paragraph({color:"blue", size:14}, "\n"+ (i+1) +": "+ slideTitle + "\n") )   
    document.paragraphs.push( TextEdit.Paragraph({}, notes +"\n") ) 
}

关于javascript - 从主题演讲中提取PresentationNotes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29908323/

相关文章:

php - 无法从 JavaScript 获取文本字段值

javascript - 我可以使用三元运算符来处理 promise 中的错误吗?

applescript - 通过 Applescript 发送电子邮件时发件人不正确

xcode - 我可以在 OS X 10.10 Yosemite 上安装 XCode 7.3 吗?

swift - 在三角形带中隐藏三角形? (以编程方式隐藏部分模型)

javascript - React - 传递的 props 被视为对象,错误提示 'objects are not valid as a react child'

javascript - 在 Windows Phone 7 上使用 FileSystemObject - IE9 Mango(和 iPhone 替代品)

javascript - 使用 JXA 单击 UI 元素不起作用

Javascript 自动化 (OSA) Yosemite : privilege error for certain StandardAddition commands

objective-c - Finder 窗口刷新问题(优胜美地)