productiveGuser.com

Run Google Apps Script inside Desktop Browser

Posted By: Harish
run basic google apps script

Open Google Apps Script editor and create a new project.

run basic google apps script

A new Code.gs file will be opened in the Apps Script editor.

A default starter function will be given. Delete that and add a function with a more meaningful function name based on our use.

For this example, let's add a function named getRootDriveFolder as we are going to print out our google drive’s root folder name.

Now add code inside that function to perform an action we need. On executing this function, either success or error output is returned .

function getRootDriveFolder() {
  let rootFolder = DriveApp.getRootFolder();
  Logger.log(rootFolder);
}

Now click on the save icon (floppy disk icon) and run the code by clicking on Run.

run basic google apps script

Saving before any code changes or addition of new methods is recommended, if not changes will be lost.

And while clicking on the Run button, please make sure that the required function is selected in the dropdown located to the right of the Debug button.

Now you will be asked to give authorization to the required google products which are used in this function.

run basic google apps script

This step is needed only for the first time access.

If google can't verify the project, you can go to advanced option of the warning and give the required access. Please give access to only your projects from your account and only if it's safe.

Don't give access to other projects without proper checking and authorization. For this example I gave the permission because I'm the only person to use this project. You can find more info on unverified apps authorization HERE.

You can also ask authorization using Google scopes. If needed, follow that guide to add a scope to your project.

After authorization, the function will run and give the output inside the Execution window. As I’m logging the result, the log can be seen in the execution window .

run basic google apps script

We can add many functions and run the required function individually.

Later in this blog, we will look into error handling and in-depth articles about running google apps scripts.

Share is Caring

Related Posts