0

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()

user1086377
  • 328
  • 5
  • 16

1 Answers1

2

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") ) 
}
wivku
  • 2,457
  • 2
  • 33
  • 42
  • How did you test getting the text? When I did slide.presenterNotes() I would get an error. running it in the shell and doing console.log(notes) would never print out text I'd get an error. Ill try it tonight when I get home . Thank you. Ill let you know if I have any issues. – user1086377 May 01 '15 at 14:07
  • There is no testing done. I checked just now using the script editor, if a slide has no speaker notes, it returns "". – wivku May 01 '15 at 14:17
  • Thanks again. Ill get back to you tonight but im pretty positive when I was doing presentationNotes() it would say not a function. Ill let you know what happens. – user1086377 May 01 '15 at 14:36
  • Could be typo? Should be presenterNotes(), not presentationNotes(). – wivku May 01 '15 at 15:03
  • WOW, hang my head in shame and cry to sleep. – user1086377 May 01 '15 at 16:44