Custom application to open .gdoc extensions - lmmx/devnotes GitHub Wiki

Make a parsing script: /usr/bin/gdocopen.sh

  • cut -d\" -f 4 is the URL, just pass it to google-chrome
google-chrome $(cut -d\" -f 4 "$@")
  • Make it executable: chmod +x /usr/bin/gdocopen.sh

Make an application to call it:

  • /usr/share/applications/gdocopen.desktop
    [Desktop Entry]
    Name=gdocopen
    Exec=google-chrome $(cut -d\" -f 4 %U)
    Terminal=false
    Type=Application
    MimeType=application/vnd.google-apps.document;

Set as default

  • First check gdoc doesn't have an associated mime-type: grep 'gdoc' /etc/mime.types
  • Add it if not: sudo vim /etc/mime.types (as per this)
application/vnd.google-apps.document				gdoc
* Set the `.desktop` file (and associated script) as default application for the new MimeType: `xdg-mime default gdocopen.desktop "application/vnd.google-apps.document"`

If this doesn't change anything

  • Remove the line and from /etc/mime.types and do it through XML
  • sudo vim /usr/share/mime/application/vnd.google-apps.document.xml
<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="application/vnd.google-apps.document">
  <glob pattern="*.gdoc"/>
</mime-type>
  • Update the system: sudo update-mime-database /usr/share/mime

👎 👎 👎 👎 👎 👎 👎 👎 👎 👎 👎 doesn't work!

  • update-mime-database deletes the xml file every time and variations on Exec= commands fail
  • file --mime-type -b ./GoogleDrive/University/{FILE}.gdoc remains text/plain

Retry application rather than MimeType

  • sudo ln -s /usr/bin/gdocopen.sh /usr/bin/gdocopen
#!/bin/bash

gdocurl=$(cut -d\" -f 4 "$@")
google-chrome "$gdocurl"
  • This works in the terminal, but fails when selected as default application in Nautilus
  • Changing MimeType in the .desktop file associated with the Nautilus application to text/plain doesn't change Nautilus seeing it as an executable text file. Not being able to change the MimeType is preventing this being as simple as a double-click
  • To open a .gdoc file you have to right click > Open with > gdocopen
  • The default is applied to all text/plain mimetype files, not just the extension as hoped
  • Change the default program for a plain text file back to a text editor. For some reason this makes Google Docs appear in the Open With dialogue for .gdoc files
⚠️ **GitHub.com Fallback** ⚠️