Moving Text Between Drafts and DEVONthink To Go with Shortcuts

November 13, 2018 by Gabe | [mmd] |

I'm still looking for a convenient way to edit text files that I archive in DEVONthink To Go. While I love the organization and intelligent search in DEVONthink the built-in text editor is anemic. I developed a pair of Shortcuts that move text between Drafts and DEVONthink.

The first Shortcut is used when send text out of DEVONthink To Go and primarily deals with the mish-mash of data that comes along with the plain text on iOS. When DTTG shares a Markdown or text document it adds the file title that includes a unique ID. This ID is then used to update text when the file comes back into DEVONthink To Go.1

I've created to Shortcuts. One is simple and handles sending the file to Drafts from DEVONthink To Go. The other is longer and using the first line in Drafts as the title of a text file.

DTTG to Drafts

When DEVONthink To Go exports a file it has two different components it sends to the share-sheet. The first has the simple name of the text file. The second component has the name with an ID suffix added. We need this ID to synchronize the file when we import changes later.

Here's the Shortcut.

DEVONthink to Drafts

The first step is to grab the text objects exported from DEVONthink To Go. The file name with the ID suffix is (so far) always contained in the second item in the object list. The Shortcut grabs this title, the file extension, and the body of the text file and creates a new text object that is then sent to Drafts. This ends the Shortcut.

File to Drafts

Drafts to DTTG

After working on this text in Drafts, I want to update the file in DEVONthink To Go. iOS already has some major limitations for text editors accessing data stored in other apps. Drafts makes it even harder because it's not a file-based app. Drafts uses a database of text, so to get data out as a file is a bit trickier.

We're going to take advantage of a feature in DEVONthink To Go which is quite clever but really non-obvious. If you import a file using the "Copy to DEVONthink" sharing extension and that file is named the same and include the ID suffix mentioned above, the contents of the file will be updated. This avoids duplicate files scattered all around DEVONthink. It doesn't matter what database or group the file is in either, which also avoids tedious browsing.

Here's that Shortcut.

Drafts to DEVONthink

This Shortcut assumes that the original unique text file ID is on the first line of the Drafts text. We extract that by splitting all of the text in Drafts and then grabbing the first line (Item At Index 1) and assigning that to a variable named "FileName" which we will use a little later.

Next we grab the Shortcut input again and count the lines of text. This will come in handy in the very next section.

At this point we have three important pieces of data:

  1. The FileName in DEVONthink To Go that will be updated with the Drafts text
  2. The number of lines in the text coming from Drafts
  3. All of the other lines in the text coming from Drafts

In pseudo-code we need to now extract the lines of text that aren't the first line. That's why we counted up the total number of lines. We simply use all of the lines of text from line 2 to the last line (Count) of the Drafts text to make the text file to send to the sharing extension.

Let's continue...

The last block of actions starts by grabbing the Shortcut input again.

Finish Him

We split it into text lines again and then use the "Get Items from List" action to grab the text from line 2 until the end (which we stored as the "Count" in a previous step).

Now that we have a list of lines we combine them back into a single block of text.

Shortcuts has a funny little feature where you can treat an incoming block of text as if it were a file. This is not obvious. To do this you must assign that block of text a name using the "Set Name" action. The name we'll use is the FileName we extracted way back at the beginning. I guess in the Shortcuts philosophy, you don't have a file unless you name it.

The final step is to send this file to the share extension.

After triggering the share sheet in Drafts, we send it to Shortcuts, then select the "Drafts to DTTG" Shortcut. Finally, we end up back at the share extension draw and use the "Copy to DEVONthink" extension to update the document in DTTG.

Export from Drafts

Text Files

I'm both fascinated and frustrated by the way iOS and apps treat text files. These are the oldest file types there are and yet Shortcuts has very few useful actions for text files. The only real first class text file editor I have on iOS is 1Writer and it does not allow editing text files in place in DEVONthink To Go.

I think iOS is missing a TextEdit equivalent that works seamlessly with the Files app and the Notes app. Heck, just give the Notes app the ability to work with text files. By abstracting away the file system, iOS has thrown away some of the foundational benefits of most other operating systems: separating our data from the applications that work with them. This is not an original complaint but it is a persistent one.

iOS enforces the concept of applications as owners of data. In the case of plain text this comes with huge trade-offs. We must rely on either Shortcut acrobatics or the kindness of developers to provide an exit. Both of these are risks create for no obvious benefit.

If you like the complexity and time consumption of working with the Shortcuts app, you'll love working with text files on iOS.


  1. Kudos to DEVONthink for treating a file object a first class citizen on iOS. It's one of the reasons I stay with the app and pretty much have it open on one device or another most of the day. 

tags

Older articles

  1. 11 Years Gone

    November 10, 2018 by Gabe | [mmd] |

    I still miss the mind of Kurt Vonnegut. His ideas shaped my own.

    Another flaw in the human character is that everybody wants to build and nobody wants to do maintenance.

    Kurt Vonnegut, Hocus Pocus

    I think of that idea often. It explains the state of the world. How did ...

  2. iPad Pro 2018 Gut Reaction

    November 08, 2018 by Gabe | [mmd] |

    After less than 24 hours with iPad Pro, here are the reactions I'd give anyone considering an upgrade.

    TL;DR: The 12.9" is still huge, the pencil is better, and the keyboard case is a big improvement. It's a pro-level iPad that's more than most people ...

  3. Standing still. iPad Pro 2018

    November 04, 2018 by Gabe | [mmd] |

    Speaking of independent Apple blogging, it's nice to see that Thomas Verschoren is back at it.

    Standing still. iPad Pro 2018

    But, even with all those new bells and whistles, it’s still the same iPad running the same iOS. It’s an iPad. A device that was perfect ...

  4. Daring Fireball: Dan Frakes Goes to Apple as Mac App Store Editor

    November 04, 2018 by Gabe | [mmd] |

    Daring Fireball: Dan Frakes Goes to Apple as Mac App Store Editor

    The talent pool writing about Apple products and platforms from outside the company’s walls is getting noticeably shallower. And on a personal level, this trend is not good for me, because I can’t link to App ...

  5. Clipboard Shortcuts with Siri

    November 01, 2018 by Gabe | [mmd] |

    While I'm frustrated by some of Shortcuts gaps, it has solved some long standing problems. I use apps like Drafts less because I can do basic clipboard transformations with Shortcuts, triggered by Siri. Here are a few the clipboard Shortcuts I use the most.

    Paste to Drafts

    This is ...

  6. Shortcuts Shenanigans

    October 31, 2018 by Gabe | [mmd] |

    I'm still trying to bend Apple's Shortcuts app to my will. I probably would have given up long ago were it not for the joy I get from my HomePod when it actually works. I've definitely run into the rough edges of Shortcuts, edges that feel like ...

  7. Calca for iOS Gets an Update

    October 26, 2018 by Gabe | [mmd] |

    Calca is a terrific little plain text calculator app that I feared was abandoned. As a fan of Markdown and all things plain text, Calca appeals to me desire for simplicity and portability. I write the text and Calca does the math.

    The latest update adds iOS 11 support which ...

  8. Screenshot Stitching with Picsew

    October 26, 2018 by Gabe | [mmd] |

    Even without the "big bucks" of affiliate links, I still have some iOS apps to recommend. I recently bought Picsew to create a single long image of a Shortcuts macro. It worked a treat.

    Point it at multiple screenshots and then export as a seamless single image.

    Picsew

    There are several ...

  9. A Siri Shortcut to Share as a Markdown File

    October 24, 2018 by Gabe | [mmd] |

    The Problem

    I'm a big fan of Drafts for iOS. It's a terrific writing environment and it can integrate with just about anything through URL schemes. But, URL schemes have a major limitation when I write long blocks of text. A URL can only support a finite number ...