Six Colors
Six Colors

by Jason Snell & Dan Moren

This Week's Sponsor

End users aren't your enemy! Kolide gets users to fix their own device compliance problems–and unsecure devices can't log in. Click here to learn how.

By Jason Snell

Command Performance: URL powerhouses

Get Contents of URL

URLs make the world go round. In their simplest form, of course, they load web pages. But there’s hidden complexity beneath the humble URL. As many people who build web pages already know, they can carry enormous amounts of data from place to place, all by tacking on extra stuff in the query portion at the end of the URL—that’s the stuff that follows the question mark symbol.

So, for example, https://my.example/?name=Jason contacts a web server and passes across the field name containing the name Jason. Of course, most URL queries are far more complicated—and they don’t always use web servers. URL, after all, stands for Uniform Resource Locator, and they can refer to apps, too. In fact, most inter-application communication on iOS takes place via the humble URL.

I’ve configured 1Writer, my primary text editor on iOS, to run a Shortcut via this URL: shortcuts://run-shortcut?name=Post%20to%20Six%20Colors%202020&input={[text]}. Shortcuts is registered as the handler for any URLs starting with shortcuts, and Shortcuts accepts requests to run a Shortcut at run-shortcut, with the name of the shortcut in the name field. In this case, I’m running a shortcut called “Post to Six Colors 2020” (the symbol %20 is how you encode the space character in URL format). As for the input field, that’s data that’s passed to the shortcut itself, for it to act upon as it sees fit. In this case, that’s {[text]}—which is actually a 1Writer command that will be replaced with the entire contents of the story I’m writing, encoded into the URL. As you might imagine, that’s a really long URL. But that’s okay, the URL can handle it. It’s resilient. How do you think it came through the Browser Wars unscathed?

There are so many different services on the Internet that offer interfaces that you can connect to via a web interface. A few of my friends created Shortcuts to interface directly with Toggl, a time-tracking app—effectively building their own time-tracking app within Shortcuts, all connecting to the Toggl web service.

You do this all via the seemingly unassuming Shortcuts action Get Contents of URL, which in its simplest form is a tool for getting the text of webpages. But if you tap Show More to expand the action, you’ll see that it’s built to interface with web apps. For my Post to Six Colors 2020 shortcut, I’m dispatching a huge amount of XML data to WordPress via the POST method, which requires that I use the Headers element to indicate I’m sending a content type of text/xml. The contents of the XML data are sent in a Magic Variable I’ve called XMLQuery.

In short, I’m able to write shortcuts that control WordPress (and before this month, Movable Type) because they’ve got open web interfaces. And pretty much any service that offers a web interface can be accessed in this way, because the web is a standard. The web interfaces of WordPress and Movable Type weren’t built with the idea that an app on an iPad would be able to access them. But because they were built to a standard, and because Shortcuts supports that standard, I’m able to control them just the same.

Oh, and speaking of URLs, the final step of my Six Colors shortcut actually opens the story I just posted via a Shortcut within the WordPress editor, for me to verify before it goes live. That, too, is an action built on a URL containing query data—because I need to specify which article I need to edit.

form command

If you’re curious about my shortcut, I’ve made it available via iCloud.

Search Six Colors