GAS AI BuilderApps Script Assistant Sign in

Share a file with someone

Apps Script recipes › Drive files

Gives one person view or edit access to a file without the notification email Google sends by default.

File Code.gs

/** Shares quietly when the Drive advanced service is on, otherwise with Google's email. */
function shareFile_(fileId, email, role) {
  if (typeof Drive !== 'undefined') {
    Drive.Permissions.create({ type: 'user', role: role === 'edit' ? 'writer' : 'reader', emailAddress: email }, fileId, { sendNotificationEmail: false });
    return;
  }
  const file = DriveApp.getFileById(fileId);
  if (role === 'edit') file.addEditor(email);
  else file.addViewer(email);
}

Good to know

Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.

Use it in a project

More in Drive files

Get or make a folder by nameFinds a folder by name inside a parent (or makes it), so files land in Reports/2026/11 without duplicates.Read the text of a PDF or photo (OCR)Turns a PDF or picture into text with Google's OCR through the Advanced Drive service (v2 or v3), then removes the temporary Doc.