Apps Script lets you share files and folders with specific users, domains, or the general public using file.addEditor(), file.addViewer(), and file.setSharing(). This is useful for automatically sharing reports with clients, granting team members access to new folders, or revoking permissions when a deal closes.
Adding an Editor to a File
functionshareWithEditor(){var file =DriveApp.getFileById("YOUR_FILE_ID"); file.addEditor("[email protected]");Logger.log("Editor access granted to [email protected]");}
functionmakePublic(){var file =DriveApp.getFileById("YOUR_FILE_ID"); file.setSharing(DriveApp.Access.ANYONE_WITH_LINK,DriveApp.Permission.VIEW);Logger.log("File is now publicly viewable: "+ file.getUrl());}