Extract PresentationNotes from keynote

故事扮演 提交于 2019-12-11 20:36:01

问题


I'm having a hard time extracting presentationNotes from a keynote presentation using JXA (Javascript for osx) I don't want to use applescript. There is way more to this script than extracting notes.

It seems rather simple. However when I get the presentationNotes its in an RichText object that doesn't seem to have anyway to get normal text. So I figured I'd open up textEditor and write them out to it. Well I can't figure out how to do that.

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.


}

Any ideas or help would be appreciated. I've seen some applescript examples, however I couldn't get them to translate. Apparently applescript as text doesn't relate to toString()


回答1:


You were almost there. You should not push the text, but push a paragraph object of the text.

Here is a complete example (text only). It uses the currently open Keynote and TextEdit documents.

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") ) 
}


来源:https://stackoverflow.com/questions/29908323/extract-presentationnotes-from-keynote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!