Basic understanding: how to create JS actions

Hello,

I am thinking about getting subscription for Drafts 5, however, I have one question regarding the development of actions: if I create an action with JS parts in Drafts, am I able to edit code on my mac somehow?
The reason is that I have only an iPhone and I am not very comfortable with typing larger code parts on screen keyboard. As far as I understand Drafts is syncing custom Actions to the iCloud anyway. Would I be able to edit the code-heavy parts on my mac then?

Javascript is just text, so technically yes you could. But until a Mac version of Drafts is available you can’t test them on your Mac; pretty much any script you make will involve some Drafts objects at some point and so you need to test it in Drafts.

You would just pass the script between your phone and Mac and copy it into wherever you need it to go on that device.

Thank you for your answer.
Do we know something about the mac version: when will it be available, will it be covered by the same subscription, etc.? (I guess not, but just in case)

Another question: does Drafts provide any help for editing JavaScript files in it? Like autocomplete, linting? There are also JS editors for iOS, would it be possible to use them for editing and writing JS scripts in drafts, now when we have files access in iOS?

The reference to a Mac version is on the Drafts web site and is as follows:

We hope to bring Drafts to the Mac. A lot of work has been done in the Drafts 5 development cycle to prepare the app to move to the Mac, but we do not have anything to announce at this time.

No one apart from Greg (@agiletortoise) is in any position to comment on the subscriptions just now, but I wouldn’t assume that it would be an additional subscription.

Drafts has syntax highlighting for JavaScript, but that’s it right now. You could pass text in and out of Drafts to another app, but a few things to keep in mind when doing this is that action steps are not Drafts so the share sheet is not going to help get the script into the action. You’ll need the. clipboard instead (though since you can export actions as an encoded URL, I guess there is technically another way). Secondly, you will have to bring it back into Drafts to test it. There’s no sandbox or framework you can load elsewhere to support it externally. Finally, even if you were using a draft as an interim staging area for the JavaScript (which you could evaluate and run without copying into an action), Drafts drafts are not separate files accessible by other apps. iCloud is just the syncing service for the data, not individual draft file storage.

Ok, thank you for the very useful information and clarification.
I will have to think about how my workflow could look like and whether it may be better to try to use pythonista for now, since source files there are easily synced via iCloud and it is a descent development environment by itself.

But I think it a shortcoming Greg should address, since the JS scripting part is getting more and more powerful and complex scripts should not be debugged with prints… Just my 2c.

You can import any JS file as a script in Drafts which does make this fairly easy.

Hi Rosemary,

can you think of any automated workflow there? I think for now the only descent option would be to get an cheap iPad with an external keyboard just for writing scripts. All other options cause more troubles than problems solved. It is a bit sad, since I already have a perfect machine for development with a good keyboard and enough power - my MacBook.

depending on what you’re doing this may be helpful:

http://support.hogbaysoftware.com/t/writing-scripts-which-run-on-both-foldingtext-and-ios-drafts-4/652

I would just try to get the logic working in JS in a mac editor (I like CodeRunner for this kind of stuff) then bring it over to Drafts to add the app-specific stuff, which is usually the easy part