Created
April 30, 2015 12:14
-
-
Save guenp/7e4e81a16aa03a477f5b to your computer and use it in GitHub Desktop.
Google apps script for creating lab journal entries with user email, date- and timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
// Add a menu with some items, some separators, and a sub-menu. | |
DocumentApp.getUi().createMenu('Utilities') | |
.addItem('New entry', 'insertDateStamp') | |
.addToUi(); | |
} | |
/** | |
* Inserts the date at the current cursor location in boldface. | |
*/ | |
function insertDateStamp() { | |
var doc = DocumentApp.getActiveDocument(); | |
var body = doc.getBody(); | |
var user = Session.getActiveUser().getEmail() | |
var date = Utilities.formatDate(new Date(), "GMT+2", "dd-MM-yyyy' @'HH:mm:ss"); // "yyyy-MM-dd'T'HH:mm:ss'Z'" | |
//body.appendPageBreak(); | |
body.appendParagraph("\n"); | |
var par = body.appendParagraph('<' + user + '> ' + date); | |
par.setBold(true); | |
body.appendHorizontalRule(); | |
var returnchar = body.appendParagraph("\r"); | |
var position = doc.newPosition(returnchar.getChild(0), 1); | |
doc.setCursor(position); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment