Search code examples
google-slides-api

Is there a way to get the ID or name of the current presentation?


Try to create a document in the same folder of the presentation but I seem to need to have the ID or name to get the ID of the parent folder and I cant seem to find any thing that does that.

Nothing that I tried worked I.e.

function getparentfolderid(){
Var ss = slidesapp.getactivepresentation();
Var tt = slidesapp(ss.getid())
Var file = driveapp.getfilebyid(ss);
var folder = file.getparents();
var parentfoldername = folder.next().getname();
logger.log(parentfoldername);
}

Solution

  • From I need the ID of the folder that my current presentation is in. of your reply, if you want to retrieve the parent folder ID of the active presentation, how about the following sample script?

    Sample script:

    Please copy and paste the following script to the script editor of Google Slide and save the script.

    function sample() {
      const s = SlidesApp.getActivePresentation();
      const fileId = s.getId();
      const file = DriveApp.getFileById(fileId);
      const parent = file.getParents().next();
      const parentFolderId = parent.getId();
      console.log(parentFolderId); // Show parent folder ID in the log.
    
      const parentFolderName = parent.getName();
      console.log(parentFolderName); // Show parent folder name in the log.
    }
    
    • When this script is run, the parent folder ID and the parent folder name can be seen in the log.

    References: