Load txt file from iCloud

How do you load text file from iCloud Drive and convert it to html so it can be displayed in html?

When you say “convert it to HTML”, what specifically are looking for? Do you have an example text file and corresponding HTML version we can use as an reference?

If you want to load an HTML file and render it, you can do the following:

let fm = FileManager.iCloud()
let dir = fm.documentsDirectory()
let fileName = "html/fun/index.html"
let path = fm.joinPath(dir, fileName)
WebView.loadFile(path, new Size(0, 300))

Your HTML file should be located somewhere I side of Scriptables folder in iCloud Drive. In the above script it’s located at html/fun/index.html.

I have a file named cool.txt that currently sits in my iCloud storage. In that file is html that I have compiled through a workflow made. I would like to access cool.txt file in iCloud then render it as a html in scriptable. I have this capability in workflow for I’m interested in accomplishing this With in this app.

If it’s inside the Scriptables iCloud Drive, youcan use the snippet I posted above. It won’t care if the file ends with .html or .txt. If it resides in another directory, you’ll need to use the DocumentPicker to open the file.

let filePaths = await DocumentPicker.present()
let filePath = filePaths[0]
WebView.loadFile(filePath, new Size(0, 300))
1 Like