Google drives can become very convoluted very quickly with folders nested inside more deeply nested folders. As such, the hard to navigate file system google drive provides, can be hard to traverse when you're not sure where the file you're looking for is located, or what the exact name is. As such, I wanted to create a simple script that would create a TOC (table of contents) for a specified directory.
- Create a google document and open it
- Click on the Extensions > Appscript menu bar item
- This will create a container-bound appscript
- Rename the file to something like Google-Drive-TOC
- Copy paste the contents from this repository's Code.gs into your script's Code.gs
- On the left hand side of your browser window, click on the Project Settings (gear icon)
- Once in project settings, enable "Show 'appsscript.json' manifest file in editor"
- Copy paste the contents from this repository's appscript.json into your script's appscript.json
You most likely don't want to run your script via this editor window, so we need do some things to handle this.
- On the left hand side of your browser window, click on Triggers (stop-watch icon)
- Click on add trigger & choose the following modes
Choose which function to run: createMenuItem
Choose which deployment should run: Head
Select event source: From document
Select event type: On Open
Failure notification settings: Notify me weekly
- Click on save
- Since it's your first trigger it will ask for permissions (look those over)
This will allow Google-Drive-TOC to:
- See and download all your Google Drive files
- View and manage documents that this application has been installed in
- See, edit, create, and delete all your Google Docs documents
- Accept them
Note: I personally don't like how many permissions it asks for, and so I do the following to clean them up
IMPORTANT: For this to work, it has to be AFTER you've already created the trigger otherwise you have to start from the beginning
- Once your trigger has been created and permissions accepted
- Go to Google Account > Security
- You will see a section called "Your Connections to third-party apps & services"
- Click on See all connections > Google-Drive-TOC (or whatever your script is called) > See details > Remove all access > Confirm
- From here, we go back to the appscript window
- Reload it, and make sure that the trigger still shows up
- On the left hand side of your browser window, make sure to click on Editor (the code bracket icon)
- On the top menu bar, select the function-to-run and make sure that it's set to "createMenuItem"
- Click Run
- From here, it will ask you for review permissions once again, but you'll notice that they're less permissions than previously requested (these are the only permissions that the script actually requires)
This will allow Google-Drive-TOC to:
- See and download all your Google Drive files
- View and manage documents that this application has been installed in
- Accept them
- You can now exit the appscript editor window
- Open your google document
- Click on Extensions > Google-Drive-TOC > Traverse Folder
- Enter the ID of the directory you wish to traverse
- Click enter and give it a little time to run and complete
Note: To get the ID of the directory you just have to visit the directory and copy the string the unique identifier in the url.
As follows:
Example: https://drive.google.com/drive/folders/2t_OAdhehfkasdkalsdjsoe-LU1/
Copied: 2t_OAdhehfkasdkalsdjsoe-LU1