Screenshot of Shortcut file in Google Drive |
Enable Drive API
In Script Editor go to Resources > Advanced Google services ... > scroll down and turn on Drive API > click OK.
The Code
Create a new file in Google Drive that will become the Shortcut:
var shortcut = Drive.newFile();Provide the new file with a title and icon type:
shortcut.title = 'My Shortcut';Now add the ID of the parent Google folder where you want the Shortcut to be created. This is required as a list within an array so it looks more daunting than it needs to be:
shortcut.mimeType = 'application/vnd.google-apps.shortcut';
shortcut.parents = [Next we create some further details about the Shortcut - such as the ID of the folder we want it to point to:
{
"id": "ENTER ID HERE"
}
];
var shortcutDetails = Drive.newFileShortcutDetails();Finally we insert the Shortcut into Google Drive:
shortcutDetails.targetId = "ENTER ID HERE";
shortcut.shortcutDetails = shortcutDetails;
Drive.Files.insert(shortcut);And that is it.
Create a Shortcut in Google Drive.gs
Hi Phil, id there any way that I can bulking create shortcuts of files and add them to the corresponding folders?
ReplyDeleteCheers
Peter
Hi Peter
DeleteSince this blog post I have not done anything further with Shortcuts. From a quick reminder of the code I have written, I don't see why it wouldn't be possible to have a list of files (to create shortcuts to) and folders (for where they should be stored) in something like a Google Sheet that you can then iterate through, yes.
Kind regards
Phil