Open folder in Google drive from Sheets UI

1,181 views
Skip to first unread message

sben...@bbchs.org

unread,
Jul 6, 2022, 2:37:18 PM7/6/22
to Google Apps Script Community
I would like to open a folder from a menu in the sheets app.  I could use a link in the sheet, but the sheet is getting cluttered so I thought I would try this. 
The folder would be owned by the user.   I thought I heard where the functionality of opening a new tab/browser window was not allowed in Apps Script, not sure though.  If anyone could point in the right direction that would be very helpful.

Clark Lind

unread,
Jul 7, 2022, 11:48:40 PM7/7/22
to Google Apps Script Community
One method is to use an HTML model dialog that would use javascript to open the desired link in a new browser window. Then it would close itself.

Example:
Code.gs:
function onOpen(event) {
  SpreadsheetApp.getUi().createMenu("My Menu")
      .addItem('Open Link', 'showDialog')
      .addToUi();
}

function showDialog() {
  var DIALOG_TITLE = "Opening File..."
  var ui = HtmlService.createTemplateFromFile('Dialog')
      .evaluate()
      .setWidth(400)
      .setHeight(190);
  SpreadsheetApp.getUi().showModalDialog(ui, DIALOG_TITLE);
}

Dialog.html:
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
        $(function() {
          openLink()
  });

function openLink() {
    window.open("YOUR_FILE_URL");
    google.script.host.close();
}
</script>
  </head>
  <body>
  </body>
</html>

Martin Hawksey

unread,
Jul 8, 2022, 8:51:05 AM7/8/22
to Google Apps Script Community
Not tested Clark's solution but it looks like it would do the job. As it happens I came across this other post from Amit Agarwal which might also be easily modified to do what you are looking for https://www.labnol.org/open-webpage-google-sheets-220507
Reply all
Reply to author
Forward
0 new messages