-
Notifications
You must be signed in to change notification settings - Fork 88
Users Drive Shortcuts
- API documentation
- Query documentation
- Python Regular Expressions Sub function
- Definitions
- Create shortcuts
- Check shortcut validity
- Delete broken shortcuts
- Delete stale shortcuts
- https://developers.google.com/drive/api/v3/reference/files
- https://developers.google.com/drive/api/v3/shortcuts
<DomainName> ::= <String>(.<String>)+
<EmailAddress> ::= <String>@<DomainName>
<DriveFolderID> ::= <String>
<DriveFolderName> ::= <String>
<DriveFileParentAttribute> ::=
(parentid <DriveFolderID>)|
(parentname <DriveFolderName>)|
(anyownerparentname <DriveFolderName>)|
(teamdriveparentid <DriveFolderID>)|
(teamdriveparent <SharedDriveName>)|
(teamdriveparentid <SharedDriveID> teamdriveparentname <DriveFolderName>)|
(teamdriveparent <SharedDriveName> teamdriveparentname <DriveFolderName>)
gam <UserTypeEntity> create|add drivefileshortcut <DriveFileEntity> [shortcutname <String>]
[<DriveFileParentAttribute>|convertparents]
[csv [todrive <ToDriveAttribute>*]] [returnidonly]
Shortcuts will be created for all files in <DriveFileEntity>
; if shortcutname <String>
is not specified, the shortcuts will be named <DriveFileName>
where <DriveFileName>
is the name of each file referenced in <DriveFileEntity>
. <String>
can contain the string #filename#
which will be replaced with
<DriveFileName>
; e.g., shortcutname "Shortcut to #filename#"
.
There are two modes of operaton:
-
<DriveFileParentAttribute>
- Create shortcuts in specific locations-
parentid <DriveFolderID>
- Folder ID. -
parentname <DriveFolderName>
- Folder name; the folder must be owned by<UserTypeEntity>
. -
anyownerparentname <DriveFolderName>
- Folder name; the folder can be owned by any user,<UserTypeEntity>
must be able to write to the folder. -
teamdriveparentid <DriveFolderID>
- Shared Drive folder ID; when used alone, this indicates a specfic Shared Drive folder. -
teamdriveparent <SharedDriveName>
- Shared Drive name; when used alone, this indicates the root level of the Shared Drive. -
teamdriveparentid <SharedDriveID> teamdriveparentname <DriveFolderName>
- A Shared Drive ID and a folder name on that Shared Drive. -
teamdriveparent <SharedDriveName> teamdriveparentname <DriveFolderName>
- A Shared Drive name and a folder name on that Shared Drive.
-
-
convertparents
- Convert all but the last parent reference in<DriveFileEntity>
to shortcuts. My testing shows that as parents are added to a file, they are added to the front of the parents list; thus, the last parent is the original parent.
If neither <DriveFileParentAttribute>
nor convertparents
are specified, the shortcut is placed in the root folder (My Drive).
When creating shortcuts in specific locations, duplicate shortcuts will not be created. A duplicate shortcut is one that is in the same folder as another shortcut of the same name pointing to the same target file/folder.
By default, the user, shortcut name(ID) and file name(ID) are displayed on stdout.
-
returnidonly
- Display just the shortcut ID of the created shortcut on stdout
Alternatively, you can direct the output to a CSV file:
-
csv [todrive <ToDriveAttribute>*]
- Write user, shortcut name, shortcut ID, file name and file ID values to a CSV file.
To retrieve the shortcut ID with returnidonly
:
Linux/MacOS
fileId=$(gam user [email protected] create drivefileshortcut ... returnidonly)
Windows PowerShell
$fileId = & gam user [email protected] create drivefileshortcut ... returnidonly
The shortcut ID will only be valid when the return code of the command is 0; program accordingly.
Create a shortcut where the shortcut name is the same as the target filename.
$ gam user testsimple create drivefileshortcut name "My Doc" parentname "Top Folder"
User: [email protected], Drive File: My Doc, Create 1 Drive File Shortcut
User: [email protected], Drive File: My Doc, Drive File Shortcut: My Doc(xxxD5Txq7Ptt_V-eQJMkW-O1ZS3EORzzz), Created
Create a shortcut where the shortcut name is different from the target filename.
$ gam user testsimple create drivefileshortcut name "My Doc" parentname "Top Folder" shortcutname "Shortcut to #filename#"
User: [email protected], Drive File: My Doc, Create 1 Drive File Shortcut
User: [email protected], Drive File: My Doc, Drive File Shortcut: Shortcut to My Doc(xxxVCDtuBaJ7bc64rbK5FTVyy6ZxQyzzz), Created
$ gam user testsimple create drivefileshortcut name "My Doc 1" parentname "Top Folder" returnidonly
xxxDmNzbA86RAacOgeGqK6n9jwV2ypzzz
The files/folders that shortcuts reference can be deleted or have their MIME type changed so that it doesn't match the MIME type specified in the shortcut. You can check the validity of shortcuts.
gam <UserTypeEntity> check drivefileshortcut <DriveFileEntity>
[csv [todrive <ToDriveAttribute>*]]
By default, the user, shortcut name(ID) and file name(ID) and validity are displayed on stdout.
Alternatively, you can direct the output to a CSV file:
-
csv [todrive <ToDriveAttribute>*]
- Write user and shortcut/target file details to a CSV file.-
User
- User email address -
name
- Shortcut file name -
id
- Shortcut file ID -
owner
- Shortcut file owner -
parentId
- Shortcut file parent -
shortcutDetails.targetId
- Target file ID in shortcut -
shortcutDetails.targetMimeType
- Target file MIME type in shortcut -
targetName
- Target file name -
targetId
- Target file ID -
targetMimeType
- Target file MIME type -
code
-- 0 - Valid shortcut:
shortcutDetails.targetId
exists andshortcutDetails.targetMimeType
matchestargetMimeType
- 1 - File
id
not found - 2 - File
id
is not a shortcut - 3 - File
shortcutDetails.targetId
not found - 4 -
shortcutDetails.targetMimeType
does not matchtargetMimeType
- 0 - Valid shortcut:
-
You can delete shortcuts that point to files that have been deleted.
my_shortcuts
is a synonym for query ('me' in owners and mimeType = 'application/vnd.google-apps.shortcut')
gam redirect csv ./Shortcuts.csv user [email protected] check drivefileshortcut my_shortcuts csv
gam csv Shortcuts.csv matchfield code 3 gam user "~owner" delete drivefile "~id"
You can delete/create shortcuts that point to files whose MIME type has changed; short cuts can't be updated.
my_shortcuts
is a synonym for query ('me' in owners and mimeType = 'application/vnd.google-apps.shortcut')
gam redirect csv ./Shortcuts.csv user [email protected] check drivefileshortcut my_shortcuts csv
gam csv Shortcuts.csv matchfield code 4 gam user "~owner" delete drivefile "~id"
gam csv Shortcuts.csv matchfield code 4 gam user "~owner" create drivefileshortcut "~targetId" parentid "~parentId" shortcutname "~name"
gam redirect csv ./TDShortcuts.csv user [email protected] print filelist select teamdriveid <SharedDriveID> showmimetype gshortcut fields id
gam redirect csv ./Shortcuts.csv user [email protected] check drivefileshortcut csvfile TDShortcuts.csv:id csv
Need more help? Ask on the GAM Discussion Group
Update History
Installation
- How to Install GAM7
- How to Update Advanced GAM to GAM7
- How to Update GAM7
- How to Upgrade from Legacy GAM
- Install GAM as Python Library
- GAM7 on Chrome OS Devices
- GAM7 on Android Devices
- Google Network Addresses
- HTTPS Proxy
- SSL Root CA Certificates
- How to Uninstall GAM7
Configuration
- Authorization
- GAM Configuration
- Running GAM7 securely on a Google Compute Engine
- Using GAM7 with a delegated admin service account
- Using GAM7 with a YubiKey
Notes and Information
- Upgrade Benefits
- Questions? Visit the GAM Discussion Forum
- Scripts
- Other Resources
- Drive REST API v3
- BNF Syntax
- GAM Return Codes
- Python Regular Expressions
- Rclone
Definitions
Command Processing
- Bulk Processing
- Command Line Parsing
- Command Logging and Progress
- Command data from Google Docs/Sheets/Storage
- CSV Special Characters
- CSV Input Filtering
- CSV Output Filtering
- Meta Commands and File Redirection
- Permission matches
- Tag Replace
- Todrive
Collections
Client Access
- Addresses
- Administrators
- Alert Center
- Aliases
- Calendars
- Calendars - Access
- Calendars - Events
- Chrome Auto Update Expiration Counts
- Chrome Browser Cloud Management
- Chrome Device Needs Attention Counts
- Chrome Installed Apps
- Chrome Policies
- Chrome Printers
- Chrome Version Counts
- Chrome Version History
- ChromeOS Devices
- Classroom - Courses
- Classroom - Guardians
- Classroom - Invitations
- Classroom - Membership
- Cloud Channel
- Cloud Identity Devices
- Cloud Identity Groups
- Cloud Identity Groups - Membership
- Cloud Identity Policies
- Cloud Storage
- Context Aware Access Levels
- Customer
- Domains
- Domains - Verification
- Domain People - Contacts & Profiles
- Domain Shared Contacts - Global Address List
- Email Audit Monitor
- Find File Owner
- Google Data Transfers
- Groups
- Groups - Membership
- Inbound SSO
- Licenses
- Mobile Devices
- Organizational Units
- Reports
- Reseller
- Resources
- Send Email
- Schemas
- Shared Drives
- Sites
- Users
- Unmanaged Accounts
- Users - Signout and Turn off 2-Step Verification
- Vault - Takeout
- Version and Help
Special Service Account Access
Service Account Access
- Users - Analytics Admin
- Users - Application Specific Passwords
- Users - Backup Verification Codes
- Users - Calendars
- Users - Calendars - Access
- Users - Calendars - Events
- Users - Chat
- Users - Classification Labels
- Users - Classroom - Profile
- Users - Deprovision
- Users - Contacts
- Users - Contacts - Delegates
- Users - Drive - File Selection
- Users - Drive - Activity/Settings
- Users - Drive - Cleanup
- Users - Drive - Comments
- Users - Drive - Copy/Move
- Users - Drive - Files-Display
- Users - Drive - Files-Manage
- Users - Drive - Orphans
- Users - Drive - Ownership
- Users - Drive - Permissions
- Users - Drive - Query
- Users - Drive - Revisions
- Users - Drive - Shortcuts
- Users - Drive - Transfer
- Users - Forms
- Users - Gmail - Client Side Encryption
- Users - Gmail - Delegates
- Users - Gmail - Filters
- Users - Gmail - Forwarding
- Users - Gmail - Labels
- Users - Gmail - Messages/Threads
- Users - Gmail - Profile
- Users - Gmail - S/MIME
- Users - Gmail - SendAs/Signature/Vacation
- Users - Gmail - Settings
- Users - Group Membership
- Users - Keep
- Users - Looker Studio
- Users - Meet
- Users - Classroom - Profile
- Users - People - Contacts & Profiles
- Users - Photo
- Users - Profile Sharing
- Users - Shared Drives
- Users - Spreadsheets
- Users - Tasks
- Users - Tokens
- Users - YouTube