I want to move the cursor to the end of the document in the beginning of my script. How do I do that?
I already know how to move the cursor to the beginning of the document as described here.
I want to move the cursor to the end of the document in the beginning of my script. How do I do that?
I already know how to move the cursor to the beginning of the document as described here.
You can try something like this:
function setCursorToEnd() {
var doc = DocumentApp.getActiveDocument();
var paragraph = doc.getBody().appendParagraph('');
var position = doc.newPosition(paragraph, 0);
doc.setCursor(position);
}
It might not be the most efficient way though
For a document that is used somewhat as a log, where content is always added to the bottom, I use an onOpen function and position the cursor at the last paragraph:
function onOpen() {
var doc = DocumentApp.getActiveDocument();
var paragraphs = doc.getBody().getParagraphs();
var position = doc.newPosition(paragraphs[paragraphs.length-1], 0);
doc.setCursor(position);
}