Skip to content

Instantly share code, notes, and snippets.

@relativeflux
Last active March 23, 2025 08:23
Show Gist options
  • Save relativeflux/032d4087245cf8aa5b21eccfbf836435 to your computer and use it in GitHub Desktop.
Save relativeflux/032d4087245cf8aa5b21eccfbf836435 to your computer and use it in GitHub Desktop.
Automatically Empty Google Drive Trash

Automatically Empty Google Drive Trash

Adapted from https://www.amixa.com/blog/2019/04/05/automatically-empty-google-drive-trash/

  1. Make sure you use Google's Chrome web browser for best results.
  2. Open Chrome and go to www.google.com.
  3. Make sure you are signed into your Google account. If not, sign in.
  4. You should obviously have Google Drive account up and running.
  5. Visit https://script.google.com/home and click NEW PROJECT
  6. Clear out the default code that appears in the next window, and paste in the following:
function createTimeDrivenTriggers() {
  ScriptApp.newTrigger('emptyThrash')
    .timeBased()
    .everyHours(1)
    .create();
}

function emptyThrash() {
  Drive.Files.emptyTrash();
}
  1. Click the Save Icon.
  2. Enter a name such as “Automatically Empty Google Drive Trash”.
  3. Click the Resources -> Advanced Google Services” menu within the Code editor.
  4. Scroll down and turn Drive API to ON.
  5. You should see a message “These services must also be enabled in the Google Cloud Platform API Dashboard”. Click that link.
  6. N.B.: If you DO NOT see the message above, click this direct link.
  7. Click ENABLE APIS AND SERVICES.
  8. Locate Google Drive API and click it.
  9. Click Enable.
  10. Return to the browser window with Advanced Google Services still open and click OK.
  11. Click the Run icon within the project editor.
  12. You should see “Authorization Required”. Click Review Permissions.
  13. Choose your Google account (this step links the script to the proper account).
  14. You will see “This app isn’t verified”. Click Advanced, then click Go to XXXX Project (unsafe).
  15. Click ALLOW.
  16. Save your project again.
  17. Go to Run->Run Function->createTimeDrivenTriggers.
  18. Hit the Timer icon.
  19. You should see your project listed under Triggers.

Your job is now scheduled to run every hour and empty your trash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment