Google-docs – How to get a Google Document to link to the editing of itself

automationgoogle docs

Imagine a published Google Document. On the bottom I want an "Edit this document" link. Is it possible to do this automatically, somehow? Maybe with a macro or similar?

Edit: Just like on a Wiki page, where one always has an EDIT button to edit the Wiki page.

Best Answer

Short answer

The "Publish to the web" feature of Google Documents doesn't include an option to add the link to edit the source document so one of the several ways to add the link like Google Apps Script and Google Documents add-on, Google Sites Gadget, JavaScript, etc. should be used.

Extended answer

Since the URL to edit a document has the file ID than the published to the web URL there are lot of ways to add the a link to edit the document at the bottom.

URL of a published to the web Google Document:
https://docs.google.com/document/d/1ZyU97pNm0wDtOziWKnToUnjtAZarpnny_8eohF8-_F0/pub

URL given by the Share feature: https://docs.google.com/document/d/1ZyU97pNm0wDtOziWKnToUnjtAZarpnny_8eohF8-_F0/edit?usp=sharing

URL given by the Google Drive get a link feature and getUrl() method:
https://docs.google.com/open?id=1ZyU97pNm0wDtOziWKnToUnjtAZarpnny_8eohF8-_F0

File ID

1ZyU97pNm0wDtOziWKnToUnjtAZarpnny_8eohF8-_F0

Considering the above, in certain scenarios could be easier to add the link manually than to automate this task.

Example

The following Google Apps Script snippet adds the URL of the document at the end of it's body.

function appendUrl() {
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();
  var text = 'Edit this document';
  var url = doc.getUrl();
  body.appendParagraph(text).setLinkUrl(url);
}

The above is the same than copying the URL of the document and insert an hyperlink at the end of the document.

References