Friday, February 03, 2017

3shrink'ing on a Mobile Device

3shrink is working well in a desktop context, so it was time to spread the love to mobile. Specifically, I wanted to be able to take a resource on my mobile phone and quickly generate a 3shrink code for it. This turned out to be straightforward to do in Tasker.

Much of the heavy lifting is done by AutoShare, a Tasker plugin that links Tasker profiles to your phone's share menu. I used geek mode to allow 3shrink to play nicely with Tasker's HTTP Get action. Finally, I created a Tasker Scene which displays the code, domain and content encoded as a window overlay.

Here's an example of 3shrink'ing a YouTube video:

And here's an example of 3shrink'ing arbitrary text:

You can see these codes work by visiting the relevant URLs: and

By naming the AutoShrink command intelligently, I can programmatically derive the correct domain from %ascommand. This allows me to have a single 3shrink Tasker Profile which handles any number of domains.

The trickiest part of this project was dealing with the inherent messiness behind Android sharing. AutoShare exposes 3 different variables: %assubject, %astext and %asfiles, which correspond to the subject, text and files being shared. There's no set standard for what will appear in each of these variables. YouTube, for example, stores the video name %assubject and the video URL in %astext. Taptalk, seems like it does the same thing, storing post titles in %assubject. However, it chooses to set %astext to the URL to the post followed by a space, followed by the post title again.

My solution was to examine %assubject %astext as one large string, and if a URL is detected, extract it, otherwise fall back on returning the whole mess. Here's the JavaScriplet that implements this logic:

var text = 
  (local('par1') === 'undefined' ? '' : local('par1')) + " " +
  (local('par2') === 'undefined' ? '' : local('par2'));

var text = text.replace(/[\n\r ]+/g, " ").trim();

var matches = text.match(/(http[^ \n\r]+)/);
if(matches) {
  setLocal('result', matches[1]);
} else {
  setLocal('result', text);

I can't tell you how helpful it was to be able to write this code as a JavaScript rather than implementing this using clunky Tasker commands. Of course this solution isn't perfect, as it's biased towards URLs. But generally, if there's a URL in the sharing context that's what I want to capture within 3shrink.

For now I'm completely ignoring %asfiles, though eventually, I'll want to account for this variable as well. For example, I can imagine having a collection of photos I want to share with someone, and 3shrink would reduce all these files to a simple 3 character code.

Up next is to reverse the process: that is, adding support for typing in a 3shrink code and expanding that to the URL or content.

However, for now, this is certainly a step in the right direction. There's just something awesome about being able to share a video, album or article on a Post-It note containing 3 characters:

No comments:

Post a Comment


Related Posts with Thumbnails