-1

I know that I can use the Google API executable to have a local script trigger a Google Apps Script. I'm wondering if I can optimize this by eliminating the Apps Script. Are there means by which I can make a message box appear in a Sheet with just a local script? Note: Simply pasting text into the sheet won't work.

For example: Person A has the Sheet open in the browser. Person B submits new data via the command line. This triggers a message box in the sheet for Person A that says "Person B submitted new data."

Rubén
  • 34,714
  • 9
  • 70
  • 166
Helen K.
  • 69
  • 7
  • 1
    What you will be using to submit the data via a command line? Have you already read about [tag:clasp]? Are you open to anyway to show a message or you have specific requirements for " a message box appear in a Sheet"? – Rubén Jun 26 '20 at 17:39
  • 1
    I don't know of a method for one user to issue a message dialog to another user via apps script. – Cooper Jun 26 '20 at 17:40
  • Do you want to do this avoiding the use of Apps script at all? – Aerials Jun 29 '20 at 08:22

2 Answers2

1

Creating a simple dialog server side:

function simpleDialog() {
  let html='<h1>Simple Dialog Title</h><form><br /><input type="text" id="text1" name="text1" /><br /><input type="button" value="Save" onClick="google.script.run.saveData(this.parentNode);" /><br /><input type="button" value="Close" onclick="google.script.host.close();" /></form>';
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Simple Dialog");
}

function saveData(obj) {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  sh.getRange(sh.getLastRow()+1,1).setValue(obj.text1);
}
Cooper
  • 59,616
  • 6
  • 23
  • 54
  • Thanks for the reply. The code you provided would exist in GAS, so in order to trigger it from my local machine I'd have to call it from my local Python script. Is this right? I'm trying learn if I can avoid having to trigger GAS and instead create the message box with just Python (or another language on the local machine). Sorry if I've misunderstand your answer. – Helen K. Jun 26 '20 at 17:42
  • I don't much about Python. – Cooper Jun 26 '20 at 17:43
  • 1
    I would guess that programs on a local pc would not have access to the Ui – Cooper Jun 26 '20 at 17:45
0

You can use the Google Apps Script to create an API that you can use on the terminal:

// Gets data from GET Requests
function doGet(e){

try{

var result;

var data = e.parameters.data;
var ss = SpreadsheetApp.getActive().getSheetByName("Data");  
ss.appendRow(data);
result = { "Result" : "ok" , "Message" : "The data was submitted" };
}catch(e){
result = { "Result" : "failed" , "Message" : "An error has ocurred: " +e };
}

return ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON); 

}

Then you need to Publish that code as Web Application.

When you publish that script then you can do this in your Terminal:

curl -X GET -L https://script.google.com/macros/s/AKfycbztjXtmKGK6nSZ2jyqwKvvFWrsT0qEmyxKvr15SjFCVQzy83TQ/exec?data=test

And you got the result:

{"Result":"ok","Message":"The data was submitted"}

Look at this document: https://docs.google.com/spreadsheets/d/1aP7w9mjblahPI3q8nHzqlVaikmzSR4Nn4q5Bd4ehbmU/edit#gid=0

Mario Zamora
  • 109
  • 7