This Week's Sponsor:

PowerPhotos

The Ultimate Toolbox for Photos on the Mac


Posts in tutorials

Chaining Tweetbot, Pythonista, Drafts, and iMessage for URLs

DraftsMessages

DraftsMessages

Last night, Tweetbot for iOS was updated with support for the Twitter 1.1 API, which, among various requirements, includes the need of linking a tweet’s timestamp – the date and time when it was sent – to its unique URL on twitter.com. In Tweetbot, you can now open the tweet detail view and tap on the timestamp to automatically open the Twitter website in your default browser; in terms of interaction, I like this change because it lets me open tweets in Google Chrome with just one tap.

In thinking about the update last night, I realized that:

  • My team and I use iMessage for daily communication;
  • The majority of URLs we share are Twitter URLs;
  • We all use Tweetbot on iOS and OS X;
  • Easier browser access means easier bookmarklet triggering;
  • Drafts can access iMessage.

And I concluded that:

  • I could chain every piece of the puzzle together;
  • Hopefully somebody else will find it useful and adapt the workflow to other similar scenarios.

Therefore, I created a browser bookmarklet, a Python script, and a Drafts action to automate the entire process and demonstrate how you can convert Twitter URLs to tweetbot:// URLs and send text from Pythonista to Drafts.

As usual, I am posting the following workflow as a proof of concept that you can modify and adapt to your needs. For instance, you can change the action that is triggered in Drafts, the x-success parameter that will be triggered, or the way Twitter links are converted to Tweetbot-specific URLs.

Read more


Chaining Multiple Apps Together with Drafts

A few weeks ago, I took a look at the automation possibilities opened by Drafts, Agile Tortoise’s multi-purpose text app. In the article, I mentioned how a bug prevented Drafts from “linking to itself” more than once:

Therefore, my idea for cross-posting was: I can link to Drafts itself, and if the first action is successful, I can link to Drafts itself again. Essentially, I wanted to leverage the built-in App.net and Twitter actions to avoid the use of any third-party app. Unfortunately, there’s a bug in the current version of Drafts that doesn’t make that kind of action work.

With an update to Drafts released yesterday, Greg Pierce has brought various improvements to the app, including support for more customizable timestamps and dates using strftime, date and time tags for file names and URL actions, and a new way to encode strings with curly brackets.

Seemingly minor, the option to more easily URL encode strings is actually a very welcome addition: like in the latest Mr. Reader, instead of forcing the user to encode a URL into a longer string, you can simply put a URL inside {{ }} and let Drafts take care of encoding it. It means I can now experiment with building more complex workflows that contain actions for more external apps and, more importantly, for “sequential” tasks in Drafts itself. Easier encoding means we construct URLs that will tell Drafts “do this, and then do that” in a single workflow.

Those who follow me on Twitter know that I’ve been trying since yesterday to see how many apps I could chain together in a workflow, mainly out of curiosity and as a “proof” of concept. First, I tweeted about a Mr. Reader -> Drafts -> Poster workflow that would take selected text from an article, convert its Markdown to HTML, and then send it to Poster; the workflow consisted of three apps chained together, but I knew I could try to accomplish something a bit more ambitious. I kept on experimenting with Drafts URLs, and eventually I managed to build a single workflow with 3 apps and 4 different tasks involved. I’m posting it here for two reasons: a) I believe it’s a quite useful workflow; and b) it can serve as an example of what Drafts can do when you understand how to properly link multiple apps together. Read more


Due Clipper For Google Chrome

When there are no actual news or notable app releases, I prefer investing my time in creating something for other people.

Continuing my ongoing series of tips on iOS URL schemes, here’s an adaptation of my existing Due bookmarklet to work better with Google Chrome for iOS (which, as I’ve pointed out several times, has a very nice URL scheme). The following code (to install it, simply copy it and paste the entire string into a bookmark) grabs a webpage’s title and URL and sends them to Due (also powered by a great URL scheme). Read more


Chrome for iOS: Send A Webpage Back To Safari Via Bookmarklet

Sort of. Here’s a fun experiment.

Today, I wanted to quickly send a URL from Chrome for iOS – my default browser – back to Safari. I know there are ways to do Safari-to-Chrome, but I wanted the opposite: from Chrome back to Safari. I needed to install some custom Mr. Reader actions, and Chrome was giving an error when tapping on the downloadable files. I figured I could make a bookmarklet to take the current webpage in Chrome and send it to Safari.

Not so fast. There’s no documented URL scheme on iOS for opening web links in Safari, except, well, the http:// scheme itself. In testing various bookmarklet ideas, I thought that replacing googlechrome with http in Jon Abrams’ bookmarklet would force Chrome to send a link to Safari. But as It Turns Out™, doing this sort of trick in Chrome for iOS:

javascript:window.open('http'+location.href.substring(4));

…simply opens a new tab in Chrome.

What I ended up using is a hack – and a very curious one – to leverage Chrome’s support for x-callback-url to open a link back into Safari. I was inspired by Cormac Relf’s script, which I discovered yesterday when he showed me another script he made for Pythonista.

javascript:window.location='googlechrome-x-callback://x-callback-url/open/?url='+encodeURIComponent(location.href)+'&x-source=Safari&x-success='+encodeURIComponent(location.href);

As you can see above, we’re telling Chrome to open a new tab using…itself. The trick, at least theoretically, is to use an encoded location.href string to call back Safari, which is registered for the http:// scheme that Chrome, in this case, opens “externally”. Displaying x-source is needed per Google’s URL scheme specification; the name you give to x-source will be displayed as a “back” button in Chrome (as shown in the image above).

This is a profoundly inelegant and ultimately flawed solution. To make this “work” you have to:

  • Type the bookmarklet’s name, because Chrome has no bookmarks bar;
  • Nothing will happen.
  • Close Chrome;
  • Re-open it;
  • A wild new tab appears!
  • Tap the Safari button. It’s super-effective.
  • Safari will launch the link, closing the additional tab Chrome decided to open.

What is going on, exactly? Via JavaScript, we’ve forced Chrome to open a tab in itself, but doing so with x-callback-url inside a bookmarklet creates, for some reason, quite a strange behavior: the tab isn’t opened unless you close and re-open Chrome, therefore partially defeating the whole purpose of this bookmarklet, which is to quickly open a webpage in Safari. But, in spite of the clunky process, a new tab with a “Safari button” is created nevertheless, allowing you to tap it to launch Safari and close Chrome’s extra tab.

My conclusion is that we have three solutions: a) it’s not possible to create a straightforward Chrome-to-Safari bookmarklet; b) it’s possible in another way that I haven’t explored; or c) it’s possible with the x-callback-url hack, but in a different way.

If you have ideas, ping me on Twitter.


Open Google Maps Directions With Siri or Launch Center Pro

Here’s a fun experiment to launch the Google Maps app via URL scheme directly into a new Directions view.

As I detailed this morning, the new Google Maps app for iPhone lets you launch specific views and modes using a URL scheme. You don’t need to be a developer to use the URL scheme; this means you’ll be able to launch the Google Maps app from Safari, Launch Center Pro, or any other launcher using the base comgooglemaps:// URL.

Google’s URL has a scheme for directions with addresses and transportation parameters. It lets you specific a starting address with the saddr parameter, and a destination address with daddr.

Further, you can instruct the URL to open a specific directionsmode, such as driving or transit.

With these parameters, it becomes possible to set up a nice automated workflow to launch directions using Siri or Launch Center Pro. Read more


From Instapaper and Pythonista To Dropbox and Evernote As PDF

I’ve already expressed my preference for archiving webpages as PDFs rather than simple “bookmarks” on an online service. When I come across a webpage that I know I want to keep for future reference, I like to generate a clean-looking PDF file with selectable text that I can rely on for years to come.

Lately, I have become obsessed with turning longer articles I find on the Internet also into PDFs for long-term archival. For as much as I like Instapaper, I can’t be sure that the service will be around in the next decades, and I don’t want my archive of longform and quality content to be lost in the cloud. So I have come up with a way to combine Instapaper with the benefit of PDFs, Dropbox, and automation to generate documents off any link or webpage, from any device, within seconds.

Yesterday I put together an iOS and OS X workflow to generate PDFs remotely on my Mac, starting from a simple bookmarklet on iOS. On an iPhone or iPad, I can simply hit a button in Safari, and wait for Pythonista to turn a webpage (that’s already been passed through Instapaper’s text bookmarklet) into an .html file in my Dropbox, which is then converted to PDF and added to Evernote. It sounds complex, but in actual practice I can go from a Safari webpage on iOS to a PDF in the Evernote app in around 30 seconds. Hopefully you’ll find this quick solution useful; feel free to modify it and/or send suggestions. Read more



Convert Twitter.com URLs to Tweetbot Links

I communicate with my team through iMessage. We’ve tried many “communication services” over the years, yet, since last Fall, we’ve always come back to Apple’s solution. It’s not perfect for us, its reliability is far from 100%, but it works.

As we keep using iMessage every day, there’s one category of “media” we’re constantly sharing: Twitter URLs. We find some cool piece of information or news on Twitter, we share it with the team. Linking back to tweets has, in a way, become our favorite type of commentary for fun, news-hunting, and everything in between.

Twitter.com URLs, though, aren’t the best way to jump back to a tweet, especially when you’re on a mobile device. When you’re on a Mac, clicking on a Twitter link will open a new browser tab, which doesn’t really bother us as we’re used to opening background tabs on our computers. But on the iPhone and iPad, it can become annoying: there’s a limit of 8 Safari tabs on the iPhone, you get yanked out of Messages, and, most of the time, mobile.twitter.com URLs just don’t work. In our team chat, we’ve speculated the “Not Found” errors we’ve seen may be related to how Tweetbot generates Twitter URLs when you hit “Copy Link to Tweet”: instead of using status in the URL slug, it uses statuses, which seems to be the reason behind erroneous redirecting on mobile devices.

We’ve come to the conclusion that we want to be able to easily copy twitter.com URLs and turn them into links based on Tweetbot’s URL scheme. Using a simple tweetbot:// URL, you can use Twitter’s status ID – the same you receive when you copy a link – to open a single tweet directly in Tweetbot. And the best part is, the same URL scheme works consistently across Tweetbot for iOS and Tweetbot for Mac. As everyone on the MacStories team is already using Tweetbot, the solution seemed obvious – plus: no more browser tabs.

The problem was finding a way to convert twitter.com URLs easily, without having to remember complex combinations of keystrokes and commands. Furthermore, as I promised my team I’d come up with a way, I had to figure out a solution to do text conversion directly on iOS.

As a result, I’ve come up with an AppleScript, a Keyboard Maestro macro, and a simple Python script to transform Twitter URLs into their Tweetbot counterparts. Read more


Send Selected OmniFocus Task to Plain Text File

I save a lot of stuff into OmniFocus: bits of text, URLs, emails. I used to save favorite tweets into it, too. The app’s Quick Entry panel is so easy to invoke and so well-integrated with core parts of OS X  that, most of the time, I find myself clipping information that shouldn’t be into OmniFocus at all. However, I also find the process of manually going through that information beneficial to my workflow: it allows me to mentally and practically separate actionable items (tasks) from things to read and things to write (Instapaper material and my future articles, essentially).

I have created a simple AppleScript to send the selected OmniFocus task to a text file. The script is meant for how I use OmniFocus; hopefully you’ll find it useful as well. Feel free to modify it.

Typically, when I decide to go through my OmniFocus inbox, I find a lot of tasks that are actually ideas of things I want to do or write. Ideas don’t go into OmniFocus. Until those ideas become actionable items, I send them to a text file so I can elaborate on them and see if they can evolve. Like I said, most of the time those ideas are for new articles.

I store all my notes in a single Apps/ directory on my Dropbox. Based off the same AppleScript, I have created a Keyboard Maestro macro to create a new text file for each processed task; this is for ideas I know will turn out to be single, standalone articles. For ideas I’m not so sure about, I prefer to append them as text to an Ideas.txt file I keep in Dropbox as an “everything bucket” for inspiration. Read more