How can I add or replace a Google Slide notes text with a hyperlink?

Viewed 930

I need to have a note created with Google Apps Script in a presentation on slide 0 where it is having a hyperlink, which I grab off a Google Sheet, attached to it. It needs to be a note not a text or image in a slide. Reason being, that URL's are only "clickable" in a slide if the presentation is put into presentation mode first.

If I do it manually, I can create a notes text, select it and attach a hyperlink. The text changes to a regular hyperlink appearance, which one can click without first of all going to presentation mode.

This is how far I came for now:

slides[0].getNotesPage().getSpeakerNotesShape().getText().setText("juhu");

But how to add the hyperlink, in this example to the string "juhu"?

If I am trying to get it done with: .setLinkUrl() it tells me:

Exception: The operation is not allowed on notes page element (g7185420b90_2_454). (line 19, file "Code")

Any ideas?

2 Answers
  • You want to put the text with the hyperlink to the note page on Google Slides.
  • You want to achieve this using Google Apps Script.

If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

In this answer, Slides service is used.

Modification points:

  • setLinkUrl() is the method of Class TextStyle.
    • From your question, when slides[0].getNotesPage().getSpeakerNotesShape().setLinkUrl(url) is run, such error occurs. I think that the reason of your issue might be this.
  • In order to set the hyperlink to the text, at first, please use getTextStyle() to the object of TextRange. This method returns the object of TextStyle.

Modified script:

When your script is modified, it becomes as follows.

var text = "juhu";
var url = "###";  // Please set the URL.

var slides = SlidesApp.getActivePresentation().getSlides();
var text = slides[0].getNotesPage().getSpeakerNotesShape().getText().setText(text);
text.getTextStyle().setLinkUrl(url);

or

var text = "juhu";
var url = "###";  // Please set the URL.

var slides = SlidesApp.getActivePresentation().getSlides();
slides[0].getNotesPage().getSpeakerNotesShape().getText().setText(text).getTextStyle().setLinkUrl(url);

References:

If I misunderstood your question and this was not the direction you want, I apologize.

You need to turn on Advanced Slides Service, then use next code to set slide's notes link:

let presentationId = SlidesApp.getActivePresentation().getId();
let presentation = Slides.Presentations.get(presentationId);

let slidesReqs = [];

slidesReqs.push({
  updateTextStyle: {
    objectId: presentation.slides[0].slideProperties.notesPage.notesProperties.speakerNotesObjectId,
    style: {
      link: {
        url: 'https://example.com'
      }
    },
    textRange: {
      type: 'ALL'
    },
    fields: 'link'
  }
});

Slides.Presentations.batchUpdate({'requests': slidesReqs}, presentationId);

Result:

enter image description here

Related