Deprecated: Return type of I::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 62

Deprecated: Return type of I::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 91

Deprecated: Return type of I::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 71

Deprecated: Return type of I::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 101

Deprecated: Return type of I::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 53

Deprecated: Return type of Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/collection.php on line 80

Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /home/public/kirby/toolkit/lib/url.php on line 135
One Tap Less | Loop your text through TextTool's transformations

Loop your text through TextTool's transformations

I've seen a lot of actions using TextTool lately, Jeffrey Kishner seems to be a bigger fan of the app than myself. That's because it is an awesome application for whoever deals with text in a iOS device. Today we gonna pick our text from Drafts, send it to Launch Center Pro where we can select the transformation, then jump to TextTool and back to Drafts, where it loops. This means you can modify your text as many times you want, isn't that cool?

I'll start by dropping a bomb:

launchpro://?url={{texttool://x-callback-url/transform?text=[[selection]]&method=[[list:Choose Transformation|Uppercase=case&case=upper|Lowercase=case&case=lower|Sentence Case=case|Capitalize=case&case=word|Comment Block=comment&style=block|Comment Slash=comment|Comment Hash=comment&style=hash|Comment Dash=comment&style=dashes|Decode=decode|Dedupe=dedupe|Deentify=deentify|Delist Asterisk=delist|Delist Dash=delist&style=dash|Delist bullet=delist&style=bullet|Delist n=delist&style=number|Detab=detab|Educate=educate|Encode=encode|Entab=entab|Entify=entify|Escape=escape|Indent Tabs=indent&style=tabs&amount=1|Indent Spaces=indent|Join Comma=join|Join Custom=join&delimiter=%2F%2Fcustom|List Asterisk=list|List Dash=list&style=dash|List bullet=list&style=bullet|List n=list&style=number|Outdent Tabs=outdent&style=tabs&amount=1|Outdent Spaces=outdent|Pop=pop|Shift=shift|Simplify=simplify|Sort Ascending=sort|Sort Descending=sort&direction=desc|Split Comma=split|Split Custom=split&delimiter=%20|Trim=trim|Uncomment Block=uncomment&style=block|Uncomment Slash=uncomment|Uncomment Hash=uncomment&style=hash|Uncomment Dash=uncomment&style=dashes|Unescape=unescape|Wrap=wrap]]&x-success=drafts%3A%2F%2Fx-callback-url%2Fcreate%3Ftext%3D%5B%5Boutput%5D%5D%26action%3DMaster%2520TextTool%26afterSuccess%3DDelete}}

Somehow, this action is quite readable compared to everything else I've been posting lately. It triggers a long list in LCP with most of the methods available in TextTool, then it launches TextTool with the chosen transformation and sends the output to Drafts, calling itself (I named the action Master TextTool). Since this action began in Drafts, I could let its curly brackets do most of the encoding for me, leaving only the x-success to be done manually.

Of course, simplicity comes with a price. What could you do if you wanted to stop the action? You couldn't, the best you could do is cancel the [list] in LCP, double press the home button, select Drafts and paste the clipboard. I thought it would be much better if we had a prompt asking if we wanted to run the action again or just send the output. Then the problems began and I ask you to follow me to learn some hardcore encoding.

We're going to build this action backwards, as I suggested in the previous article. As with any recursive workflow, the last action is the one that calls itself (or not, in our case). The need for a control prompt gave us two desired outcomes:

drafts://x-callback-url/create?text=<encoded text>
drafts://x-callback-url/create?text=<encoded text>&action=Master%20TextTool&afterSuccess=Delete

This would become a list in Launch Center Pro:

drafts://x-callback-url/create?text=<encoded text>&[[list:Run Again?|YES=action=Master%20TextTool&afterSuccess=Delete|NO=afterSuccess=Nothing]]

Which would be called using LCP's url parameter, therefore, our return to Drafts must be double encoded, including our text:

launchpro://?url=drafts%3A%2F%2Fx-callback-url%2Fcreate%3Ftext%3D<double encoded text>%26%5B%5Blist%3ARun%20Again%3F%7CYES%3Daction%3DMaster%2520TextTool%26afterSuccess%3DDelete%7CNO%3DafterSuccess%3DNothing%5D%5D

Now you think, just encode the whole brick, set as the x-success from TextTool and run it, however, the problem here is how to send the result from TextTool to Launch Center Pro.

After you transform your text, unless specified, TextTool will place the result in the clipboard. That's our first method. Still, TextTool offers its own [[output]] parameter to submit the result in the callback and skip the clipboard. This is how you would try it:

launchpro://?url=drafts%3A%2F%2Fx-callback-url%2Fcreate%3Ftext%3D[[output]]%26%5B%5Blist%3ARun%20Again%3F%7CYES%3Daction%3DMaster%2520TextTool%26afterSuccess%3DDelete%7CNO%3DafterSuccess%3DNothing%5D%5D

This won't work, as you can imagine, since the output, which is encoded once, is decoded when it reaches Launch Center Pro, breaking any multi-line or spaced string. Then you think, just tell LCP to re-encode it. Well, that would be quite easy, let's camouflage some curly brackets wrapping our output:

launchpro://?url=drafts%3A%2F%2Fx-callback-url%2Fcreate%3Ftext%3D%7B%7B[[output]]%7D%7D%26%5B%5Blist%3ARun%20Again%3F%7CYES%3Daction%3DMaster%2520TextTool%26afterSuccess%3DDelete%7CNO%3DafterSuccess%3DNothing%5D%5D

This should work, right? Yet it doesn't. I think it is a bug from Launch Center Pro, but if you try this callback, it will join every line, removing the line breaks. This is what happens:

  1. TextTool sends the single-encoded text;
  2. Launch Center Pro decodes the url and identifies the output wrapped in curly brackets;
  3. Launch Center Pro encodes the output.

The problem lies in the last step, as Launch Center Pro ignores the line breaks. Since we're failing here, we have to appeal to the clipboard and I'll tell you why that method works.

Using [clipboard] in Launch Center Pro delays by one bounce the decoding of our TextTool outcome. Confused? Think that when we use [[output]], the first thing that happens is that the text is decoded, meanwhile, using the clipboard, this is the moment when Launch Center Pro sees your request. By the next step, when LCP would be encoding the [[output]] and skipping the line breaks, it is resolving a beautifully encoded clipboard.

drafts://x-callback-url/create?text=[clipboard]&[[list:Run Again?|YES=action=Master%20TextTool&afterSuccess=Delete|NO=afterSuccess=Nothing]]

Encode this once, attach the url call from LCP and encode it again:

launchpro%3A%2F%2F%3Furl%3Ddrafts%253A%252F%252Fx-callback-url%252Fcreate%253Ftext%253D%255Bclipboard%255D%2526%255B%255Blist%253ARun%2520Again%253F%257CYES%253Daction%253DMaster%252520TextTool%2526afterSuccess%253DDelete%257CNO%253DafterSuccess%253DNothing%255D%255D

We can finally build our TextTool action and choose our method with a [list]. The list I included previously covers almost everything TextTool has to offer, but I suggest you customize it for your personal use (removing a couple of actions wouldn't harm too).

texttool://x-callback-url/transform?text=<encoded text>&method=[[list:Choose Transformation]]&x-success=launchpro%3A%2F%2F%3Furl%3Ddrafts%253A%252F%252Fx-callback-url%252Fcreate%253Ftext%253D%255Bclipboard%255D%2526%255B%255Blist%253ARun%2520Again%253F%257CYES%253Daction%253DMaster%252520TextTool%2526afterSuccess%253DDelete%257CNO%253DafterSuccess%253DNothing%255D%255D

Now we must encode that thing, include the url prefix for Launch Center Pro and find a way to send the text. Since we're launching the action from Drafts, we can just wrap everything in curly brackets and use one of its template tags. I recommend [[selection]] as it grabs the selected text and when there's none it behaves like [[draft]], which is much more versatile. This works because Drafts resolves all its template tags before encoding.

I'll leave the full workflow for download here, but I'll attach the code with every method in the list covering a single line so you can edit, remove the line breaks and add to Drafts manually.

Master TextTool:

launchpro://?url={{texttool://x-callback-url/transform?text=[[selection]]&method=[[list:Choose Transformation|

Uppercase=case&case=upper|
Lowercase=case&case=lower|
Sentence Case=case|
Capitalize=case&case=word|
Comment Block=comment&style=block|
Comment Slash=comment|
Comment Hash=comment&style=hash|
Comment Dash=comment&style=dashes|
Decode=decode|
Dedupe=dedupe|
Deentify=deentify|
Delist Asterisk=delist|
Delist Dash=delist&style=dash|
Delist bullet=delist&style=bullet|
Delist n=delist&style=number|
Detab=detab|
Educate=educate|
Encode=encode|
Entab=entab|
Entify=entify|
Escape=escape|
Indent Tabs=indent&style=tabs&amount=1|
Indent Spaces=indent|
Join Comma=join|
Join Custom=join&delimiter=%2F%2Fcustom|
List Asterisk=list|
List Dash=list&style=dash|
List bullet=list&style=bullet|
List n=list&style=number|
Outdent Tabs=outdent&style=tabs&amount=1|
Outdent Spaces=outdent|
Pop=pop|
Shift=shift|
Simplify=simplify|
Sort Ascending=sort|
Sort Descending=sort&direction=desc|
Split Comma=split|
Split Custom=split&delimiter=%20|
Trim=trim|
Uncomment Block=uncomment&style=block|
Uncomment Slash=uncomment|
Uncomment Hash=uncomment&style=hash|
Uncomment Dash=uncomment&style=dashes|
Unescape=unescape|
Wrap=wrap

]]&x-success=launchpro%3A%2F%2F%3Furl%3Ddrafts%253A%252F%252Fx-callback-url%252Fcreate%253Ftext%253D%255Bclipboard%255D%2526%255B%255Blist%253ARun%2520again%253F%257CYES%253Daction%253DMaster%252520TextTool%2526afterSuccess%253DDelete%257CNO%253DafterSuccess%253DNothing%255D%255D}}

A few tips before you customize the action list:

  • Don't forget the vertical bar (|) after every item but the last one;
  • If you're using something that requires input, for example, split or join, encode the delimiter. I included an example in the list.

Well, I don't think I'll need a TextTool action ever again now.