I am new to Drafts5 and scripting, but tried using the scripting action to import a named text file from iCloud to create a new draft. I know you can manually import a file by long pressing the new Drafts import button, but want to do this using script as part of a larger multi-step action.
I set up a folder called Test at the root level of my iCloud directory and put a text file in there called “Test.txt” with some placeholder text in it.
The code I used to read the file was cut from the Drafts Filemanager and Drafts reference and pasted into the script action as follows:
// read from file in iCloud var fmCloud = FileManager.createCloud(); // iCloud var myDraft = fmCloud.read("/Test Folder/Test.txt") var d = Draft.create(); d.content = myDraft; d.update();
I can read the file okay but can’t seem to write it on to the blank draft I ran the action from or to a new draft in my Draft’s inbox.
Does anyone know how to write the content of the text file I read to a draft? I saw the write the method but don’t know how to use it.