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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh90Ds68nmCwPni26rHzu8XEjYFUNFyanOp41DNRHYh5OBsnb6mtD4VwKHfQKWfIh-Rv5AMeX2iQBq9bhvWLj4jsSfnMtJkEJIUrJgnKjx1Fsom3uPR_GKBjaxWVgXyfwiuyFJR/s320/Screenshot_20170203-064826.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2fBjseQ824OU3cds9yYub13A1VY6zRmqlfDDZ400BwwBXY8XOXYqKTD88_mZCIKs5CaGMCuRV5QUok-42eLPEAnK4OODToErje9u74LPQsuRDTCTuY3fb3kf-fD5WDeGhn9Z1/s320/Screenshot_20170203-064838.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhzHM6ulgkOUBTlNheEzEDgdcqqqANnWdvzA_NTOp5-F0mpoozE8OJlNR69VG9jOEx6Y9LKYxITBLFkAfXaY7EWCDNEkXQZw7wuD2fCT0SJW4VIzJ3xXCaUVIjNwOiUBQdbiyY/s320/Screenshot_20170203-064847.png)
And here's an example of 3shrink'ing arbitrary text:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEAgahfhIHVaWiu5zfG22WCKHiZl0FHx_my5zGQhquheG5BTjl-agyK5DxRsahDSEBTW9wUjF7fSbUN97TCcflv5LSdHVKuBT-ID83LPRJCTjAdig2uPYu1pMO25awBAoo5uq2/s320/Screenshot_20170203-064717.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjis2K_KtR3rfc3u9caA-OsW2PD12Pg__c2w5nhdgXcY8KOFzLQfA-ucrP2sfoHH-Rjl_pbYLf8xSUv3M8MZ5DWGauPcO1kadN2TnPWq2L_J8K4KZy0SDCkaDjhGP6Gq7lsJwcx/s320/Screenshot_20170203-064729.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcBERNGge1n0Vs_b9JR3NtJUoLSRvRy1IQjmgs6gqwQYlHpk7UlDj6CSuM1mMFEXFI2RZk29MPRMtzaV2wMWlHcMqmHnBBil21_7lMyEKJJSpcjXhzkUxOnT2NPGpPSdd1aZ1b/s320/Screenshot_20170203-064739.png)
You can see these codes work by visiting the relevant URLs: http://projx.3shrink.com/ALN and http://projx.3shrink.com/DN3.
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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAll-JvZprKCH2VXisMIDkTxUXS7Ke5hXQqHDD582T2kOSgJI0HSnCit-OkVWFbHkE-FdkGRSZLMCHEcuBKCHDnXZeK45z4Hr6zjkmI6C5y1uOatKnXBRIFE_WxGnbyh3B24Y3/s320/20170203_101437.jpg)
No comments:
Post a Comment