The collection of scripts in this apps_script
directory allows you to convert
the contents of Google Drive folders and Gmail to Markdown files that are
compatible with Docs Agent.
The steps are:
- Prepare a Google Drive folder.
- Mount Google Drive on your host machine.
- Create an Apps Script project.
- Edit and run main.gs on Apps Script.
- Update config.yaml to include the mounted directory.
First, create a new folder in Google Drive and add your Google Docs (which will be used as source documents to Docs Agent) to the folder.
Do the following:
- Browser to https://drive.google.com/.
- Click + New on the top left corner.
- Click New folder.
- Name your new folder (for example,
my source Google Docs
). - To enter the newly created folder, double click the folder.
- Add (or move) your source Google Docs to this new folder.
Mount your Google Drive to your host machine, so that it becomes easy to access the folders in Google Drive from your host machine (later in step 5).
There are a variety of methods and tools available online that enable this setup
(for example, see google-drive-ocamlfuse
for Linux machines).
Create a new Apps Script project and copy all the .gs
scripts in this
apps_script
directory to your new Apps Script project.
Do the following:
- Browse to https://script.google.com/.
- Click New Project.
- At the top of the page, click Untitled Project and enter a meaningful
title (for example,
gDocs to Docs Agent
). - Click the + icon next to Files.
- Click Script.
- Name the new script to be one of the
.gs
files in thisapps_script
directory (for example,drive_to_markdown
). - Copy the content of the
.gs
file to the new script on your Apps Script project. - To save, click the "Save project" icon in the toolbar.
- Repeat the steps until all the
.gs
files are copied to your Apps Script project. - Click the + icon next to Services.
- Scroll down and click Drive API.
- Select v2.
- Click Add.
You are now ready to edit the parameters on the main.gs
file to select a folder
in Google Drive and export emails from Gmail.
Figure 1. A screenshot of an example Apps Script project.
Edit the main.gs
file on your Apps Script project to select which functions
(features) you want to run.
Do the following:
-
Browse to your project on https://script.google.com/.
-
Open the
main.gs
file. -
In the
main
function, comment out any functions that you don't want to run (see Figure 1):-
convertDriveFolderToMDForDocsAgent(folderInput)
: This function converts the contents of a Google Drive folder to Markdown files (currently only Google Docs and PDF). Make sure to specify a valid Google Drive folder in thefolderInput
variable. Use the name of the folder created in step 1 above, for example:var folderInput = "my source Google Docs" function main() { convertDriveFolderToMDForDocsAgent(folderInput); //exportEmailsToMarkdown(SEARCH_QUERY, folderOutput); }
-
exportEmailsToMarkdown(SEARCH_QUERY, folderOutput)
: This function converts the emails returned from a Gmail search query into Markdown files. Make sure to specify a search query in theSEARCH_QUERY
variable. You can test this search query directly in the Gmail search bar. Also, specify an output directory for the resulting emails.
-
-
To save, click the "Save project" icon in the toolbar.
-
Click the "Run" icon in the toolbar.
When this script runs successfully, the Execution log panel prints output similar to the following:
9:55:59 PM Notice Execution completed
Also, the script creates a new folder in your Google Drive and stores the converted Markdown files in this folder. The name of this new folder has
-output
as a postfix. For example, with the folder namemy source Google Docs
, the name of the new folder ismy source Google Docs-output
.With Google Drive mounted on your host machine in step 2, you can now directly access this folder from the host machine, for example:
user@hostname:~/DriveFileStream/My Drive/my source Google Docs-output$ ls Copy_of_My_Google_Docs_To_Be_Converted.md
Once you have your Google Drive mounted on the host machine, you can now specify one of its folders as an input source directory for Docs Agent.
Do the following:
-
In the Docs Agent project, open the
config.yaml
file with a text editor. -
Specify your mounted Google Drive folder as an
input
group, for example:input: - path: "/usr/local/home/user01/DriveFileStream/My Drive/my source Google Docs-output" url_prefix: "docs.google.com"
You must specify a value to the
url_prefix
field, such asdocs.google.com
. Currently this value is used to generate hashes for the content. -
(Optional) Add an additional Google Drive folder for your exported emails, for example:
input: - path: "/usr/local/home/user01/DriveFileStream/My Drive/my source Google Docs-output" url_prefix: "docs.google.com" - path: "/usr/local/home/user01/DriveFileStream/My Drive/psa-output" url_prefix: "mail.google.com"
-
Save the changes in the
config.yaml
file.
You're all set with a new documentation source for Docs Agent. You can now follow the
instructions in the project's main README
file to launch the Docs Agent app.