CLI

List

gdrive files list --max 1000 --order-by "folder,name_natural" --query "trashed = false and '<email>' in readers"

Share

gdrive permissions share --type user --role reader --email <email> <file_id>

Revoke Permissions

  1. Run removeFoldersAccess to revoke permissions from folders
  2. Run revokeFilesPermissions to revoke permissions from files

After each execution that has timed out, we should copy and paste back in the continuation token and call DriveApp.continueFolderIterator() to continue the script at the pervious stopping point

Logs will be saved to _scripts/logs in the format of <yyyymmddhhmmss>_revoke_<folders|files>_permissions.json, with the following structure indicating the folders/files where the permissions from viewers have been revoked

[
    {
        "id": "",
        "name": "",
        "path": "",
        "url": "",
        "viewers": [
            {
                "name": "",
                "email" "",
                "photoUrl": ""
            }
        ]
    }
]

Download View-Only

PDF

  1. Open the PDF
  2. Paste the script into console, which handles auto scrolling and downloading
  3. OCR the PDF to make the words searchable, single/batch processing
ocrmypdf -O2 <in>.pdf <out>.pdf
mkdir output && parallel --tag -j 2 ocrmypdf -O2 '{}' 'output/{}' ::: *.pdf

Cite

https://github.com/zeltox/Google-Drive-PDF-Downloader
https://codingcat.codes/2019/01/09/download-view-protected-pdf-google-drive-js-code/

Google Doc

  1. Change/edit to /mobilebasic
  2. Disable javasciprt
  3. Save as PDF

Google Slides

  1. Change /edit to /htmlpresent
  2. Disable JavaScript
  3. document.body.style.background = "#ffffff"
  4. Remove <noscript> and extra strings inside HTML
  5. Save as PDF

OR

  1. Change /edit to /htmlpresent
  2. Paste the below script to download all slides as images
  3. Convert into PDF
let i = 0
const images = $$(".slide-content");
 
const interval = setInterval(() => {
    const anchor = document.createElement("a");
    anchor.href = images[i].style.backgroundImage.slice(5, -2).toString();
    
    anchor.download = (i + 1) + ".png";
    
    document.body.appendChild(anchor);
    anchor.click();
    document.body.removeChild(anchor);
 
    if (i + 1 === images.length) {
        clearInterval(interval);
    }
    
    i++;
}, 200)

Google Sheets

  1. Change /edit to /preview
  2. Save as PDF

Image Folder

  1. Allow pop up
// Image class selector
// Since there is authentication, need to manually download
$$('.a-b-ta-Ua').forEach((e) => {
    window.open(e.src)
})