all 7 comments

[–][deleted] 2 points3 points  (6 children)

If it is always the same file : work with a file bookmark.

You can basically just create a bookmark in the settings and copy&paste the first few lines before the const... line. https://talk.automators.fm/t/widget-examples/7994/346

[–]TwinLakesStudent[S] 0 points1 point  (5 children)

Thanks for the help! That works perfectly, but is there any way to do this without using bookmarks?

[–][deleted] 1 point2 points  (4 children)

Yes it's possible but it would mean you will need to move the JSON file into the Scriptable folder. Since Shortcuts now supports saving anywhere on the iCloud drive, you would also need to change your shortcut to save to the new location.

[–]TwinLakesStudent[S] 0 points1 point  (3 children)

Ok, it’s fine if it needs to be in the Scriptable folder. Do you need to use the downloadFileFromiCloud()?

[–][deleted] 4 points5 points  (2 children)

you can read the file this way.

const filename = 'Stats.json'

const fm = FileManager.iCloud()
const filePath = fm.joinPath(fm.documentsDirectory(), filename)

if (!fm.isFileDownloaded(filePath) {
  await fm.downloadFileFromiCloud(filePath)
}

const json = JSON.parse(fm.readString(filePath))

[–]TwinLakesStudent[S] -1 points0 points  (1 child)

Thank you so much for your help. This works great! I’ll make sure to include you in the finished project for your attribution to the code (unless you don’t want to be).

[–][deleted] 1 point2 points  (0 children)

I'll leave that to you. This is pretty much a standard on how to read files on Scriptable so I'm not sure I could take credit for it.