# Link to iCloud Drive File | Shortcuts Library

> Generate direct link to provided iCloud Drive file & seamlessly manage duplicate and expired shares.

## What this shortcut does

Link to iCloud Drive File
Generate direct link to provided iCloud Drive file & seamlessly manage duplicate and expired shares.
This Shortcut parses the original link generated by Apple’s Mail Drop service, via the “Get link to” action, so that instead of a link to an interstitial download page that then requires interacting with a download button, it provides a direct link to the file so the download occurs immediately. These files always expire after 30 days.
The selected file
must exist within iCloud Drive’s filesystem
otherwise this does not work. Anyone with the link will have access, effectively meaning it is public.
Additionally, this Shortcut seamlessly manages duplicate and expired share links, through its advanced link management framework.
Highlights of this Shortcut
Return a direct download link to shared file, not default interstitial download page.
Handle Share Sheet shortcomings for “Get link to” action on non-MacOS devices.
Keep track of all shared files, for a hands-off approach to file management.
Keep tally of the total size of all files shared.
Prevent duplicate file shares, and return existing share URL if not expired.
Delete duplicate file share if expired, and return a new share URL.
Delete any expired file shares if the total size of shared files reaches the limit, and decrements the tally of the total size of all files shared.
Validate against file and share constraints set by Mail Drop, iCloud Drive, and the Shortcut itself.
Validate against environment, such as paths, having an active internet connection, determining if on Wi-fi, etc.
Run from Share Sheet (iOS/iPadOS) in Files app, Quick Action menu (MacOS) in Finder, or as a standalone Shortcut.
Easy to use for non-technical people.
Auto-update checking (v1.0.5)
Highlights for developers
Control flow can be modified by specifying runtime input options. When needed, recommendation would be to run this Shortcut from another, and within that other Shortcut specify the runtime input options, so this one is untouched.
Shortcut returns a link at the very end as output, which allows it to be used as input that can be passed when run by other shortcuts.
Log data and state data of all shared files is kept within
iCloudDrive/Shortcuts/[shortcut-name]
.
Copious amount of comments that describe details about services, shortcomings and solutions, as well as reasons behind certain logical decisions.
Something else worth noting for developers is that
this Shortcut will always only try to do one thing
, and do it very well: return a direct link to an iCloud Drive file. That means it will not concern itself with adding many knobs and dials. In other words, besides being regarded as the simplest way to get a direct link to an iCloud Drive file and keeping track of it, this Shortcut should also be regarded as a core function to build other Shortcuts that want to utilize shared iCloud Drive files.
Do you want to return a QR code instead? Do you want to return a shortened URL? Do you want to return the original link? Do you want be able to select multiple files and directories to share? Do you want to do that and archive it before sending? Do you want this whole thing to run without notifications and alerts? Create a new Shortcut, define optional runtime parameters, build new Shortcut Input, and then pass it to this one with the “Run Shortcut” action. In the end, a direct link will be provided and it will be up to another Shortcut developer to plan how they want to expand on that functionality. When the urge to edit the source strikes, ask first whether it can be extended instead by compositing it within another Shortcut. Legitimate new use cases, such as useful runtime input options can always be discussed add added to the core in future versions.
Runtime input to specify arguments or options that modify control flow logic
This is done by copying a dictionary to clipboard in a Shortcut that runs this one. The copy to clipboard should occur immediately before calling this one, and ideally it should be configured for “Local Only” copying, so that universal clipboard is not leveraged.
The dictionary from the clipboard is merged with the default runtime input dictionary here and matching keys from the updated runtime inputs replace the defaults. This approach scales to any number of arguments and options without the need to modify the logic right away. The runtime inputs can then be leveraged in the Shortcut to control flow logic.
Merging logic
Any default inputs defined here are merged with the modified inputs. They way they are merged are that the first key in a dictionary wins out, so when two dictionaries are merged, the modified ones are set first, and the defaults are set second. Any keys that exist in the second one are discarded if they are already in the first. So far the merging logic seems predictable and constant.
Options
None of the options documented here are set by default. The default behaviours in this Shortcut are implied by its logic. It is up to any Shortcut that runs this one whether it should specify these options and modify that default behaviour. Restoring a default behaviour is done by not specifying an option.
Note
that due to Apple’s “Use smart quotes and dashes” keyboard toggle that seems to have no effect in Shortcuts, beware of specifying options prefixed with an em-dash (“—“) instead of a double dash (“--“). In shell-speak, these are long options.
These options are best utilitized by creating a new Shortcut that calls the current one with these options. Note that in the future I will publish the debugger Shortcut used to help develop this one.
--debug
: Execute Shortcut in debug mode, which means much more output during its runtime. By default this Shortcut does not run in debug mode.
--emulate-sharesheet-issue
: This emulates the Share Sheet issue on non-MacOS devices that makes a File Path equal to a File Name. When File Path does not include its actual path information, the Share Sheet fix is triggered.
--example
: This is an example option that does nothing. Flow control is not modified by it, and serves only as an example of how to specify options. It also helps in showing how runtime inputs are merged.
--link-original
: Return the original share URL generated by Mail Drop, which means instead of a direct download link, Mail Drop’s interstitial download page URL will be returned. By default this Shortcut returns a direct download link.
--no-clipboard-copy
: Do not copy the link to clipboard at the end of the Shortcut’s execution. By default this Shortcut copies the link to clipboard.
--only-garbage-collect
: This option will only execute garbage collection and then stop. In other words, no file needs to be provided and even if there was it would be ignored. This will simply run the garbage collection operation and stop. By default this Shortcut option is not set. There are are mutliple conditions that would automatically trigger this operation, so unless there is an explicit need to execute just this operation, it is better to let it operate as designed.
--quiet
: Suppress most warning and confirmation prompts and proceed non-interactively. Irrecoverable errors will break out of quiet mode with notifications. Questions that are asked on the first run are also not being suppressed, as they need to be saved to config. By default this Shortcut is interactive when needed.
Reasons behind this Shortcut
iCloud Drive provides up to 14TB of storage to users with maxed out subscriptions, and yet when needing to share a direct link to a file, there are numerous obstables that push those users to alternatives that can be untrusted, unreliable, cost as much or, more simply, are just redundant. These users already have access to storage but they are unable to maximize the benefits of their subscription to do something as straightforward as sharing a direct link to a file in the good old fashioned sense of sharing a file over the Internet. This is disappointing and makes iCloud Drive seem incapable of what should be its most basic utility.
The obstacles that force users to reach for other services are, for example, that 1) the link to a shared file is always indirect and obfuscated behind an interstitial page, which means the link to the file is not actually to
the
file. A user who receives the link will need to interact with their browser to then click a download button. That’s not a great experience. Another example is that 2) in order to share a file in the iCloud Drive ecosystem, there are several obscure and easy-to-miss toggles that a user needs to configure for defining Access, such as “Anyone with the link” and Permissions such as “View only,” which are especially tedious because the end result is still an interstitial page that requires clicking on a download button in a browser. The experience is even further degraded by the fact that the direct download link constantly changes, so attempting to discover a direct link from the interstitial page that is static and can be referenced by other utilities, services, or environments for more than an hour is a useless exercise; users are stuck with a locked-down “collaboration” mode of sorts that does not really meet the need.
This Shortcut restores that rudimentary use-case of just wanting direct access to a file over the Internet from another location. This is relevant whether the file is 20KB or 50GB, and more. Maybe the receiving end is just someone who wants a random file, no strings attached. Maybe it’s a shell environment. Maybe it’s an HTML document. Maybe it’s a streaming video player? Maybe it’s another Shortcut. Maybe it’s some ‘nix l33tbro who looks down on Apple from their fart-infused Aeron. Who knows? The point is that the file itself will be treated precisely as the asset and type that it is: there are no guard rails, no training wheels, no helmets. Feel like sharing something perilous, like,
gasp
, a “zip” file, or worse, a file
without
an extension? Yearning for the laxity of a 90s Internet? Go on, you anarchist.
Permissions needed in
Info (i) > Privacy
tab
Open URLs (the generated link).
Log Shortcut state information and configs to files (Files app / Finder).
Append or delete its own state information and config files (Files app / Finder).
Send notifications.
Copy to clipboard.
For convenience, choosing
Always Allow
will make future runs much faster.
If issues running the Shortcut persists, click the
Reset Privacy
button located in this tab.
Compatibility
This works iOS, iPadOS, and MacOS. Note that mobile operating systems like iOS and iPadOS force files within the Files app to download to device before they are shared, while on MacOS files in Finder that are offloaded to iCloud Drive will not force a download, which means if there’s a need to share a very large file, like 80GB, it is better to share from MacOS. Nevertheless, should there be an abundance of bandwidth and local storage available on those mobile operating systems, this Shortcut will work as usual.
Shortcuts using this one
Shortly after this Shortcut is published, several other Shortcuts that use this one as a core dependency will be published, not just because they will demonstrate extension through composition, but because these other Shortcuts are also useful and used by the author regularly.
Author
@author Dane MacMillan
[email protected]

## Compatibility

iPhone, iPad, Mac

## Required apps

Files, iCloud Drive

[View this page](https://shortcutlibrary.app/shortcuts/link-to-icloud-drive-file)

[Download Shortcuts Library on the App Store](https://apps.apple.com/app/id6759494377)
