This is a sample script for creating a shortcut on Google Drive using Google Apps Script.
Sample script
Before you run the script, please enable Drive API at Advanced Google services.
function createShortcut(targetId, name, folderId) {
const resource = {
shortcutDetails: { targetId: targetId },
title: name,
mimeType: "application/vnd.google-apps.shortcut",
};
if (folderId) resource.parents = [{ id: folderId }];
const shortcut = Drive.Files.insert(resource);
return shortcut.id;
}
// Please run this function.
function main() {
const targetId = "###"; // Please set the ID of target file or folder.
const shortcutName = "###"; // Please set the shortcut name.
const folderId = "###"; // Please set the folder ID for putting the created shortcut.
const id = createShortcut(targetId, shortcutName, folderId);
console.log(id);
}
References
-
-
The official document says as follows.
Note: Apps creating shortcuts with files.insert must specify the MIME type application/vnd.google-apps.drive-sdk.
- But, when
application/vnd.google-apps.drive-sdk
is used, the shortcut couldn’t be created. I’m not sure whether this is the bug or the current specification. So I usedapplication/vnd.google-apps.shortcut
as the mimeType.
- But, when
-
-
This sample script was answered to this question.