I’ve been trying to read and write to a JSON file I have store in my shortcuts folder on iCloud Drive. I’d like to eventually build some shortcuts that return information about objects in the JSON file or append to objects, etc.
Issue I’m running into is that I’m getting errors when I try to read the JSON file from a hardcoded string file path. Works fine when I get the file path using
DocumentPicker.openFile(). I got the hardcoded path by just feeding the result of
Pasteboard.copyString(). What am I missing?
Error: Cannot download the file from iCloud because the file does not exist
Here is my code when it works (does’t work when I comment out
pathDocPicker and replace with
let pathHardCoded = "/var/mobile/Library/Mobile Documents/iCloud~is~workflow~my~workflows/Documents/timestamps.json" let pathDocPicker = await DocumentPicker.openFile(); // pathHardCoded === pathDocPicker returns true; let fm = FileManager.iCloud(); await fm.downloadFileFromiCloud(pathDocPicker) let text = fm.read(pathDocPicker) let rawString = text.toRawString() let parsedData = JSON.parse(rawString); QuickLook.present(parsedData)
EDIT: One more note. I tried putting my JSON file in the Scriptable folder in iCloud Drive, then copying the path to that and use that as
let pathHardCoded = "/var/mobile/Library/Mobile Documents/iCloud~dk~simonbs~Scriptable/Documents/timestamps.json"
When I do that, it reads the file! Why does it work in the Scriptable folder and not in any other folder when I hardcode the path?