iOS Shortcut for opening iCloud files

(This is my first post here. Please be gentle.)

I’ve only recently come to Scrivener 3 and am still familiarizing myself with it, though I have made some progress. One of the things that I’ve found a bit difficult to work with in regards to the iOS version is viewing research files (largely PDFs). On the Mac, of course, one has the options to import research files into the project file or—thankfully—to simply link to them. The latter is especially useful for iOS users so the file does not grow too large and thereafter take a a worryingly long time to sync (or is it ‘synch’?—that does not look right). Yet then the iOS project file, though lighter, is left all alone, with no nifty links to its associated research.

I have tried several solutions over the last few days: an abortive attempt at using symlinks using URIs; using URI links to each file, saved in a document in the project (under Research, of course) to open files saved within PDF Expert; using Shortcuts to open iCloud files in Scrivener itself, which leads to the file being copied into the project file and consequently requiring my remembering to delete them before syncing; and finally a particular shortcut which presents a list of files from which one selects the file and it opens in PDF Expert, though it could be told to open in any installed/appropriate app. It’s the latter that I wanted to share as I think others may find it useful. I spent a few hours getting it right, so it should save someone else some time by sharing it.

Here’s an image of the shortcut steps:

To put this together, simply open the Shortcuts app, use the search box in the upper right to find each of the steps (‘Get contents of folder’, ‘Choose from List’, ‘Open File in App’), and as they appear in the right sidebar, click on each to add them to the left pane. Once they’re in there and you’ve altered them to your preferences—folder name and app—click Done. You can test it by clicking the right-pointing ‘Run’ arrow at the top of the screen.

Regarding the first step, the directory in which your files are—‘Research’ in the image above—is selected by clicking on the initial empty value ‘Folder’. It will need to be either an iCloud folder or a local folder—one in ‘On my iPad’ or ‘On my iPhone’. Those are all that the Shortcuts app presents as options, somewhat surprisingly.

In the third step, the app to open the file in—‘PDF Expert’ in the image above—is also chosen by clicking the intial empty value ‘Default App’. (PDF Expert is my ‘Default App’ in any case, but it’s also my preferred app for reading PDFs.) Any appropriate installed app may be chosen.

Once the shortcut is saved, one need only save a link in a reference file within the project, using the URI to the shortcut. Using the example of the image above for a shortcut named ‘Open File Menu’, that URI will be:

The URI requires the use of %20 for each space appearing in the name of the shortcut. When creating the link, make certain to select ‘No prefix’. Save and sync and try it out.

Upon clicking the link, the Shortcuts app will—perhaps alarmingly—open and begin running the shortcut. Do not panic. That’s just how this works. A scrollable list of the files in the directory will be presented. Click one, and the selected app will open and display the chosen file in the chosen app. At that point, I split my screen with PDF Expert and Scrivener. It take a little more screen space to do that rather than to import and view the file in Scrivener, and it’s only side-by-side currently, but I find it a viable alternative to filling my project file with many files.

There are some limitations with this. The folders to be listed may only be iCloud folders or ‘On my iPad/iPhone’ folders. Dropbox folders and folders within apps are not an option, and are greyed-out in the selection panel. (I was surprised that Dropbox was not available in that regard; I suppose it is because it is, in the iPadOS/iOS environmentm its own sandboxed app.) Also, any subfolders in your chosen iCloud folder will appear in the list as though it were a file, rather than a folder to click into and in which to choose a file. If you have subfolders, there are two solutions to this: 1.) in setting up the shortcut, in the first step, ‘Get contents of folder’, click the right-pointing circled arrow and flip the switch for ‘Recursive’. This will list all the files in the chosen folder and in all subfolders in the scrollable list for selection and opening; 2.) create similar shortcuts for any subfolders. Neither option is ideal, but these are current limitations in these shortcuts perhaps to be resolved in the future. (If there is a solution to the subfolder issue, I should very much like to hear of it; I was not able to find one, though that certainly doesn’t mean that there isn’t one.)

In any case, I hope others find this useful. Best --Kevin.