Slides Auto Date
A client wanted a way to insert today's date automatically into his slides so his students could know today's date. Right now there is not a function in Slides to insert date, so I have documented here the work around to accomplish this.
It is done with a spreadsheet, using the =TODAY() formula in a cell, then copying the cell or multiple cells and then pasting the table (series of cells) using the 'link to spreadsheet' option. This will allow you to update the date on your slide each day by clicking the update button that appears on the pasted table in the slide.
How to create a menu in a Google Doc to be able to insert today's date at the cursor
//This creates the menu
function onOpen() {
var ui = DocumentApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Utilities')
.addItem('Insert Date', 'insertAtCursor')
.addToUi();
}
//Inserts the date at the current cursor location in boldface and italic.
function insertAtCursor() {
var cursor = DocumentApp.getActiveDocument().getCursor();
if (cursor) {
// Attempt to insert text at the cursor position. If insertion returns null,
// then the cursor's containing element doesn't allow text insertions.
var date = Utilities.formatDate(new Date(), "GMT", "MM-dd-yyyy"); // "yyyy-MM-dd'T'HH:mm:ss'Z'"
var element = cursor.insertText(date);
if (element) {
element.setBold(true);
element.setItalic(true);
} else {
DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor in the document.');
}
}
- Copy this script
- Open a google doc
- Go to Tools/Script Editor
- Higlight the text in the editor and delete it and then paste in this script
- Save and name the project
- Refresh the google doc
- A new menu appears called utilities
- On first run you need to authorize
- Today's date is inserted at the cursor
- This script has it set to bold and italic, you can change that in the script by changing the element.setBold(true) or element.setItalic(true) to (false).
This is an autodate doc example. You can also make a copy of this document, and it will contain the script.