Alejandro93sa
Alejandro93sa

Reputation: 177

Way to execute Google Standalone Script directly from Drive

Well, I've been reading the documentation for a long time but, as per usual, it's really unclear...

I'm developing a Google Script with the Script Editor that is already working as expected (it have nothing to see with any G suite program but with Drive).

By now, the only way to execute it is opening the script editor and press on the "play" button or the "execute" bar and press on the function.

Obviously this is not a solution since anyone from the bussines could modify/see the code.

So the question is this: how can I make from this script something like an "exe" that I just have to double ckick (its obviously located at Drive) and it executes the script?

I saw this but seems it says no way to do it except from opening the code and execute from the google app script editor...

Upvotes: 2

Views: 1744

Answers (3)

Cooper
Cooper

Reputation: 64040

Try this:

  1. Build the menu first.
  2. Click "Run My Code".
  3. Click the "Run My Code" button.

runmycode.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
    function runMyCode()
    {
      google.script.run
         .withSuccessHandler(updateMyDiv)
         .myFunctionName();
    }
    function updateMyDiv(hl)
    {
      document.getElementById('MyDiv').innerHTML+='<br />'+ hl;
    }
    </script>
  </head>
  <body>
  <input type="button" value="Run My Code" onclick="runMyCode()" />
   <div id="MyDiv"></div>
  </body>
</html>

runMyCode.gs:

function myFunctionName() {
  return "Your function has run";
}

function startYourSideBar()
{
   var ui=HtmlService.createHtmlOutputFromFile('runmycode');
   SpreadsheetApp.getUi().showSidebar(ui);
}

function buildMenu()
{
  SpreadsheetApp.getUi().createMenu('Run My Code') 
     .addItem('Run My Code', 'startYourSideBar')
     .addToUi()
}

Upvotes: 0

Alan Wells
Alan Wells

Reputation: 31300

A Web App is triggered by either an HTTPS GET or POST request. You don't need to use Google Drive.

Ways to trigger a Web App:

  • Chrome Extension - You can create a Chrome Extension to make an HTTPS GET or POST request. The user would need to install the Chrome extension, and the Chrome extension could put a button in the browser.
  • Link - Some HTML with a link in it. An email with a link in it. Click the link.
  • Address Bar - Browser's address bar - Every browser's address bar issues an HTTPS GET request, so you can run a Web App directly from the address bar. Put the published Web App url into the browser address bar and click whatever the browser uses to load the page. (Only for a GET request)
  • Bookmark - The user could bookmark the link to your Web App. So, they would need to click the link in their bookmark.
  • Any program that can make an HTTPS GET or POST request. For example, make a POST request from Python or C++.

For a GET request, you need a doGet() function in your script, and to react to a POST request you need a doPost() function.

Upvotes: 3

Serge insas
Serge insas

Reputation: 46794

From what I understand of your requirements the only way would be to deploy your script as a web app with a minimal user interface, just a short message to confirm proper execution for example.

You will never have a "local" executable file since everything in Apps Script is done on google's servers, not in our computers. Instead you will have an url... (with the advantage that it is completely OS independent ! )

The script will remain private unless you share it and you'll be able to choose who can use that url.

Upvotes: 1

Related Questions