DEV Community

A quick way to create Google documents.

Mark Nicol on November 03, 2018

A question - triggered by a quick productivity tip a colleague showed me this week. If you are a Google Drive / Documents user you can create a ne...
Collapse
 
kaelscion profile image
kaelscion

I saw this post and it got me thinking. You can totally do this programmatically with Python. The script below is Python 3, but this would work with 2 as well without the 'f' string:


import requests
import webbrowser

def open_google_doc(doc_type):
    r = requests.get(f'https://{doc_type}.new')
    webbrowser.open(r.url)

open_google_doc('sheets')

Something tells me this has potential of some sort, but I have no idea what it would be. Let me know if any of you could think of a reason to use this :P

Collapse
 
kaelscion profile image
kaelscion

For me, my inner web-scraping wonders if there are other browser commands that can be exploited in a similar way. Perhaps the correct json data in a header for requests could open and append data to a new document. Then, a different request could read it back. Perhaps this could be used for a quick notes web app, or filtering system for data you currently have in a spreadsheet, or retrieve a particular slide? That way you can do quick, one-off reads and writes from a front end UI that leverages the in-place cloud infrastructure of the g suite rather than building your own? Then anybody who can collaborate on those docs could do the same, no Docs API key necessary. Hmm....would this be the type of framework any web devs would find useful?

Collapse
 
mark_nicol profile image
Mark Nicol

That is an interesting thought. I'll now be pondering that one too, but I have no good answers.

A very crude way of logging when an event happened?

Collapse
 
mark_nicol profile image
Mark Nicol • Edited

Yes. I've found that one super useful in the past when you already have the app open on another doc. Is there any smart keyboard shortcut for opening one of the office apps? - I know you can use windows key or cmd-r and then select the application.

Collapse
 
nektro profile image
Meghan (she/her)

Works in Firefox too 🤔🤔🤔

Collapse
 
mark_nicol profile image
Mark Nicol

Yes, you are quite right, digging a wee bit it looks like it should work just about anywhere.

The 'magic' seems to be in the '.new'. What it seems to be doing is requests are redirected to a google document creation URL. (e.g. doc.new becomes a request to docs.google.com/document/u/0/create) - which from the quartz article was an older hack for the same thing.

Collapse
 
nektro profile image
Meghan (she/her)

Ah, didn’t realize new was a valid TLD

Collapse
 
nektro profile image
Meghan (she/her)

⌘ is the replacement for CTRL in pretty much every shortcut on macOS

 
mark_nicol profile image
Mark Nicol

Thanks, I've not tried Clavier+. Will take a look. You've reminded me that I used to find a similar tool called KeyText dead handy for quick scripts in Windows.