January 11, 2020 at 11:08 PM by Dr. Drang
The documentation for the new action (which you can see within Shortcuts by tapping the ⓘ, is this:
This is correct, but as we’ll see in a minute, there’s an even easier way to pass information into an inline script.
|0||This shortcut takes the URL of the tweet.|
|1||Do an HTTP GET on the tweet URL.|
|2||Treat the data from the GET as HTML.|
|3||Find the meta tag that has the text of the tweet.|
|4||Extract the text of the tweet from the match; this will include HTML entities.|
|5||Because the next step turns newline characters into spaces, protect them by turning them into runs of 10 equals signs (we’ll turn them back later).|
|6||Convert all the remaining HTML entities into characters by converting the HTML to rich text.|
|7||Convert the rich text into plain text so Scriptable can handle it.|
|9||It’s impossible to see, but there’s a newline in this text box.|
|10||Convert the runs of equals signs we created in Step 5 back into newlines.|
|11||Display the converted text in an alert.|
(I’m trying out a new way to describe Shortcuts—a table of the actions with a column of step numbers to the left and a column of commentary to the right. It’s a pain in the ass to make, but I think it gives the reader a better way to understand what’s going on. If people find it useful, I’ll try to figure out a way to automate the creation of the screenshots of the individual actions and their assembly into a table.)
The ROT13 conversion is done using the same code we used earlier. The difference between this and the standalone script is in the simpler input on Line 10 and output on Line 12.
For input, we don’t have to pass a parameter and use the
❑Text on the right-hand side of Line 10 is my plain text attempt to show the magic variable (which you can see in the screenshot); it’s the one bound to the output text from Step 8.
Similarly, we don’t have to use
Script.setShortcutOutput() for output—we can just
return the output value and later steps in the shortcut can use it (this is described in the documentation). If you need to return something more complex than a string of text, you can generate JSON by doing something like
and then using the “Get Dictionary from Input” action.
Fundamentally, what Scriptable’s new inline action does is address the problem John Gruber complained about in his tweet:
@jsnell @drdrang @leoncowle This whole thread is fun but it just shows how ridiculous it is that the Shortcuts doesn’t allow, you know, actual scripting. I’m mean it’s ROT13.
John Gruber Dec 26, 2019 – 10:45 PM
If you have Scriptable, you can now do, you know, actual scripting in Shortcuts.