Get Script's own name

28 views
Skip to first unread message

Mike Castle

unread,
Sep 7, 2026, 2:15:44 PM (3 days ago) Sep 7
to google-apps-sc...@googlegroups.com
Silly basic question time.

I've not started a Web App in a while and relearning the basics.

I want to do something like:

function doGet() {
const appName = some_magic_function(...);
return HtmlService.createHtmlOutput('<p>Hello, world!</p>').setTitle(appName);
}

where `appName` ends up being the name of the saved GAS project.

Basically, I rename the project and my web page changes name.

In looking through my old projects, it looks like I simply used a
global variable instead:

const APP_NAME = 'My funky app';

I'm guessing that I would need to do something like
ScriptApp.getScriptId() and look that up via DriveApp?

Or am I, hopefully, missing something basic?

Thanks,
mrc

Keith Andersen

unread,
Sep 7, 2026, 2:26:34 PM (3 days ago) Sep 7
to google-apps-sc...@googlegroups.com
function doGet() {
  const scriptId = ScriptApp.getScriptId();
  const appName = DriveApp.getFileById(scriptId).getName();
  
  return HtmlService.createHtmlOutput('<p>Hello, world!</p>').setTitle(appName);
}


Just know that making a Drive API call on every page load introduces slight latency. If performance is a priority, caching the project name using CacheService or sticking with a top-level const APP_NAME constant avoids the extra API call and scope requirements.



My website: https://sites.google.com/view/klaweb/
Passions: God, Family, Scriptures, Learning, Data Management, Google Sheets + App Script and much more!



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/CA%2Bt9iMxjgzwy%2BXEciV0G0WqsS-M%3DQm0AOC0sz1JaeZo0agV7zg%40mail.gmail.com.

Mike Castle

unread,
Sep 7, 2026, 2:37:45 PM (3 days ago) Sep 7
to google-apps-sc...@googlegroups.com
On Mon, Sep 7, 2026 at 11:26 AM Keith Andersen
<contact...@gmail.com> wrote:
>
> function doGet() {
> const scriptId = ScriptApp.getScriptId();
> const appName = DriveApp.getFileById(scriptId).getName();
>
> return HtmlService.createHtmlOutput('<p>Hello, world!</p>').setTitle(appName);
> }
>
>
> Just know that making a Drive API call on every page load introduces slight latency. If performance is a priority, caching the project name using CacheService or sticking with a top-level const APP_NAME constant avoids the extra API call and scope requirements.

Pretty much what I thought. I was hoping to avoid that extra call.

Thanks!
mrc

Keith Andersen

unread,
Sep 7, 2026, 2:44:52 PM (3 days ago) Sep 7
to google-apps-sc...@googlegroups.com
👍👍



My website: https://sites.google.com/view/klaweb/
Passions: God, Family, Scriptures, Learning, Data Management, Google Sheets + App Script and much more!
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages