Tag Archives: Google Apps Script

Automatically Empty Google Drive Trash

Want to empty your Google Drive Trash automatically?  I finally have the solution for you.

  1. Make sure you are signed into your Google account.
  2. You should OBVIOUSLY have Google Drive account up and running since that’s why you’re here, right?
  3. Go here https://script.google.com/home
  4. Click NEW SCRIPT
  5. Paste in this code (exactly)
    function createTimeDrivenTriggers() {
      ScriptApp.newTrigger('emptyThrash')
          .timeBased()
          .everyHours(1)
          .create();
    }

    function emptyThrash()
    {
    Drive.Files.emptyTrash();
    }

  6. Click the Save Icon
  7. Enter a name such as “Automatically Empty Google Drive Trash”
  8. Click the “Resources -> Advanced Google Services” menu within the Code editor
  9.  Scroll down and turn “Drive API” to “ON”
  10. You should see a message “These services must also be enabled in the Google Cloud Platform API Dashboard”.  Click that link.
  11. Click “ENABLE APIS AND SERVICES”
  12. Locate “Google Drive API” and click it.
  13. Click Enable
  14. Go back to your browser window with the “Advanced Google Services” window still open.
  15. Click OK
  16. Click the “Run” icon within the project editor
  17. You should see “Authorization Required”.  Click Review Permissions
  18. Choose your google account (this links up the script with the proper account).
  19. You will see “This app isn’t verified”.  Click Advanced. Click Go to XXXX Project (unsafe).
  20. Click ALLOW
  21. Save your project again.
  22. Go to “Run->Run Function->createTimeDrivenTriggers”
  23. Hit the “Timer” icon.
  24. You should see your project listed under “Triggers”
  25. Your job is now scheduled to run every 1 hour and empty your trash!

 

This process was crafted by deciphering the following two pages:

https://stackoverflow.com/questions/32749289/automatically-delete-file-from-google-drive-trash

https://stackoverflow.com/questions/25749906/permanently-delete-file-from-google-drive/32749203