In this case, how about using Drive API? I think that you can set them using Drive API. In this answer, the method of "Files: update" of Drive API v3 is used.
Sample script:
Before you use this script, please enable Drive API at Advanced Google services.
function myFunction() {
const fileId = "###"; // Please set the file ID.
const url = "https://www.googleapis.com/drive/v3/files/" + fileId;
const res = UrlFetchApp.fetch(url, {
method: "patch",
headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()},
contentType: "application/json",
payload: JSON.stringify({viewersCanCopyContent: false, writersCanShare: false}),
});
console.log(res.getContentText())
// DriveApp.createFile(blob) // This comment line is used for automatically detecting the scope of "https://www.googleapis.com/auth/drive"
}
Note:
writersCanShare
is for "Editors can change permissions and share"
viewersCanCopyContent
is for "Viewers and commenters can see the option to download, print, and copy"
- When I saw the official document,
viewersCanCopyContent
says Warning: This item is deprecated. Deprecated - use copyRequiresWriterPermission instead.
. But when copyRequiresWriterPermission
is used, this check couldn't controle. So, in this answer, I used viewersCanCopyContent
.
- For the future update,
{viewersCanCopyContent: false, copyRequiresWriterPermission: false, writersCanShare: false}
might be suitable instead of {viewersCanCopyContent: false, writersCanShare: false}
.
Above sample, both checks are unchecked.
When copyRequiresWriterPermission
can be used, I think that Drive API v2 might be able to use it as follows. But when I tested it now, it seems that "Viewers and commenters can see the option to download, print, and copy" cannot be controled.
Drive.Files.patch({copyRequiresWriterPermission:false,writersCanShare:false}, fileId);
For example, when viewersCanCopyContent: true, writersCanShare: true
are used, both checks are checked.
References:
setShareableByEditors
is for "Editors can change permissions and share" in your comment. Do you know the method for controlling "Viewers and commenters can see the option to download, print, and copy" in Drive service? – Tanaike