0

I've written a short script in the Google Apps Script online editor to read my Google Calendar events for a particular day and determine when I am available. The goal is to produce some text that I can copy into a scheduling email, like this:

  • 1/6, 10:00-11:30am EST
  • 1/6, 12:45-3:00pm EST
  • 1/6, 4:00-5:30pm EST

I can log these lines and then view logs in the web interface, but the log entries have these awkward timestamps at the beginning that I have to remove manually after copying. For example:

  • [19-01-04 21:51:48:835 PST] 1/6, 10:00-11:30am EST
  • [19-01-04 21:51:48:836 PST] 1/6, 12:45-3:00pm EST
  • [19-01-04 21:51:48:836 PST] 1/6, 4:00-5:30pm EST

As a workaround, I would like my script to write the lines to a text file and then download this file to my computer. Answers to similar questions, such as this one, involve SpreadsheetApp objects (I'm using the Calendar, not Sheets, API) and creating UI elements (I'd like to do this without a UI). Can I trigger such a download directly in the script?

1 Answers1

0

Instead of or as well as logging to the console, you could use

var body = '';

// Under each console log statement, use
body += loggedData + "\n";

// Change 'loggedData' for the appropriate variable, etc.

MailApp.sendEmail('you@yourdomain.com', 'subject', body);

EDIT

You could take it a step further and create a draft email with the data already in it.

GmailApp.createDraft('', 'subject', body);

You can add the recipient from Gmail when accessing your drafts. (You may have to refresh the page to see it).

CalamitousCode
  • 1,324
  • 1
  • 14
  • 21