Skip to content

Writing .gdoc files from a web browser

lmmx edited this page Dec 26, 2014 · 22 revisions

.gdoc files are converted to Word but the format is very simple

{"url": "<b>URL</b>", "resource_id": "document: <b>ID</b>" }

in which the URL contains the ID:

https://docs.google.com/document/d/**ID**/edit?usp=docslist_api

thus the files can be written knowing just the ID ($ID):

{"url": "https://docs.google.com/document/d/$ID/edit?usp=docslist_api", "resource_id": "document: $ID" }

The files in a folder can be Javascript-parsed with:

icons = document.querySelectorAll('div[aria-label*="Google Docs"][class="k-u-P-m"]');
var TitleRegEx = new RegExp("Google\ Docs$","g")
var thesedocs = [];
for (i=0;i<icons.length;i++) {
    if (icons[i].parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('aria-label') == "Folder list view") {
    	var thisdoc =['',''];
    	thisdoc[0] = icons[i].getAttribute('aria-label').replace(TitleRegEx, "").trim();
    	thisdoc[1] = icons[i].getAttribute('data-id');
    	thesedocs.push(thisdoc.join('\t'));
    }
}
console.log(thesedocs.join('\n'));
// copy(thesedocs.join('\n'));

The output can be pasted into tab-separated files for each folder, gdoc-list.tsv.

for gdoclist in ./*/gdoc-list.tsv; do
gdocdir=$(dirname "$gdoclist")
while read gdocline; do
  gdocTitle=$(echo "$gdocline" | cut -d $'\t' -f 1)
  gdocID=$(echo "$gdocline" | cut -d $'\t' -f 2)
  echo '{"url": "https://docs.google.com/document/d/'"$gdocID"'/edit?usp=docslist_api", "resource_id": "document: "'"$gdocID"'" }' > "$gdocdir/$gdocTitle".gdoc;
done <"$gdoclist"
done
Clone this wiki locally