Best practices for working with “Working Copy”

I’m curious about how folks are working with “Working Copy” now. I know Drafts doesn’t have a file structure underneath, making it somewhat less well suited than iaWriter or similar (as described in Federico Viticci’s article), but it can write/read from iCloud Drive. I wonder if there’s a way to script something that would allow you to open a file from a Working Copy repo, edit it, and save back to working copy with commit message that’s as easy as Federico describes. The action in the directory that supports working copy will write to a repo, but doesn’t have a way to grab the file (https://actions.getdrafts.com/a/1Pe). I know I can “import” the file via Drafts interface, but that doesn’t bring in the file name which that action requests.

I guess I’m just wondering before I dive into the rabbit hole here whether folks have cooked up anything that works really smoothly for them that they’d be willing to share. I’m sort of wondering if I’m about to make things more complicated than necessary …

1 Like

I do almost exactly this for my diary. I open a template from working copy and then save it back to another repo. I use pythonista however for the retrieval because my javascript skills are quite bad :slight_smile:

If you’re intrested I can post the script and the action to save it to working copy.

2 Likes

thanks for the offer. I know a bare minimum of javascript and zero python, so I’lll probably fumble around with some javascript instead of diving into pythonista. thanks though!

Well, in case anyone else is curious about this, the Working Copy url scheme is actually quite forgiving and allows you to go spelunking around in different repos instead of specifying things exactly.

Basically, you can either import a file into Drafts from Working Copy using the native Drafts import function via the Files app, or use the following URL in an action to navigate to any repo and file in WC itself:

working-copy://x-callback-url/read/?x-success=drafts5%3A%2F%2Fx-callback-url%2Fcreate%3Ftext%3D

Then, after you’ve made some changes, you can write those back to Working Copy with the following URL, which opens WC, prompts you to select the repo and file, then asks you to confirm overwriting the file, then prompts for commit message. Once committed, you come back to drafts.

working-copy://x-callback-url/write/?text=%5B%5Bdraft%5D%5D&askcommit=1&x-success=drafts5%3A%2F%2F

Obviously, if you’re working on a specific file frequently or repo, you can add those parameters to the URL, either hard coding them in via the URL or via variables that you can set up in a prompt box or whatever. Much easier than I anticipated.

2 Likes

Thanks for that. It’s on my list of things to dig into and you’ve saved me some spadework!