13

Is there a way to insert an automatic "last edited" timestamp in the footer of a Google Document?

I would like to make sure that time stamp is on the document when I print. I figure out how to enter a "today" time stamp but need a script to pull "last edited" and, if possible, the user that last edited.

0

2 Answers 2

5

Yes, there is. Use file.lastModifyingUserName and file.modifiedDate.

Example:

function lastEdited() {
  var doc = DocumentApp.getActiveDocument();
  var id = doc.getId();
  var file = Drive.Files.get(id);
  var footerSection = (doc.getFooter())?doc.getFooter():doc.addFooter();
  footerSection.clear();
  var userName = file.lastModifyingUserName;
  var date = file.modifiedDate;
  var text = '[Last edited by ' + userName + ' on ' + Utilities.formatDate(new Date(date), 'GMT+5', 'YYYY/MM/dd hh:mm') + ']';
  var p = footerSection.insertParagraph(0,text);
  p.setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}

NOTES:

  1. To use the above script you should enable the Google Drive Advanced service as is described in - https://developers.google.com/apps-script/guides/services/advanced

References

0
-1

This was a good start, but it didn't require all the functionality that was needed for me. The correct timezone, the correct place in the document for it to be inserted. The ability to add gif images and updating live text and time since last edit.

https://docs.google.com/document/d/10rL7P3NQ-DOX1c1KyP0wJ6vkdNy9ee2xfCtr90RpAOQ/edit?usp=sharing

This script is a Google Apps Script written in JavaScript that is designed to work with Google Docs. Its primary purpose is to perform various functions related to tracking and displaying information about related the time since the last edit of a Google Doc. More over, the script interacts with the document, access user properties, and make modifications to the document's content based on the time elapsed since the last edit.

I hope someone finds this useful and learns from it. Maybe they will help make this code better. If you like, I would be happy to hear your thoughts.

2
  • Can you include the code in the post?
    – Laurel
    Commented Nov 7, 2023 at 13:46
  • Welcome to Web Applications SE. The context of this answer is not clear. What do you mean by "This was a good start"? Please bear in mind that this is not a discussion forum. When posting an answer, please ensure that it answers the question and is self-contained. If it is relevant to mention something said in a previous answer or refer to it, please refer to it by date, author, or other non-ambiguous means. The answer order is not always reliable and might vary from one user to another due to the answer sort option. Ref. How to Answer. Commented Nov 7, 2023 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.