2

I'm trying to write a function to delete notes from Google Slides presentation using Google Apps Script.

I went through the examples and assume I need to match that to something like https://developers.google.com/slides/samples/writing#delete_a_page_or_page_element by calling speakers notes using https://developers.google.com/slides/how-tos/notes, but I can't make the link.

New to Google Apps Script, any help appreciated.

Kos
  • 4,890
  • 9
  • 38
  • 42
user3306720
  • 93
  • 1
  • 1
  • 5

3 Answers3

2

Thanks for the initial script! Unfortunately it didn't work for me, and after several attempts, I've made it work:

function clearNotes(){
    var presentation = SlidesApp.getActivePresentation();
    var presentationId = presentation.getId();
    var slides = presentation.getSlides();

    var requests = [];

    slides.forEach(function(slide, i) {
        var slideNote = slide.getObjectId(); 
        var slideNotesPage = slide.getNotesPage();
        var shape = slideNotesPage.getSpeakerNotesShape();
        var shapeText = shape.getText();

        if(shapeText != undefined){

           shapeText.clear();
        }
    })
    if(requests.length > 0){
        var batchUpdateResponse = Slides.Presentations.batchUpdate({requests: requests}, presentationId);
    }
}

As a newbie, it involved lots of try and error, debug and follow the guide here: https://developers.google.com/apps-script/reference/slides/text-range.html#clear()

So far, it's the only solution I've found to batch delete all notes in a Google Slides presentation.

Hope this helps, Rafa.

0

Here is how I did it.

function clearNotes(){
    var presentation = SlidesApp.getActivePresentation();
    var presentationId = presentation.getId();
    var slides = presentation.getSlides();

    var requests = [];

    slides.forEach(function(slide, i) {
        var slideNote = Slides.Presentations.Pages.get(presentationId, slide.getObjectId()); 
        var slideNoteId = JSON.parse(slideNote).slideProperties.notesPage.notesProperties.speakerNotesObjectId;

        var slideNotesPage = JSON.parse(slideNote).slideProperties.notesPage;
        var shapeText = slideNotesPage.pageElements[1].shape.text;

        if(shapeText != undefined){
        requests.push({
            deleteText: {objectId: slideNoteId,textRange:{type: 'ALL'}}
        });
        }
    })
    if(requests.length > 0){
        var batchUpdateResponse = Slides.Presentations.batchUpdate({requests: requests}, presentationId);
    }
}

Hope it helps.

Urvah Shabbir
  • 945
  • 2
  • 15
  • 46
0

Google has now integrated this option into the Slides program. When you make a copy you can choose/check to include notes or not.

Check boxes show options when creating copy of current Slides presentation

user3306720
  • 93
  • 1
  • 1
  • 5