Feb 13

Using a Text Service to quickly open a web page URL

Category: apple,mac,macosx,tips

From time to time I buy products online via eBay or AliExpress. I use a Tap Forms 5 database to track my orders and make sure I keep track of everything from when I ordered it to when it arrives. Tap Forms 5 however doesn’t have a feature that let’s me take the value of a random field and template that into a URL (I should probably ask for that). However the Mac has a powerful framework called “Services” that allows you to hook into applications and execute code. One of the easiest ways to build a service is to use Automator.

Automator enables us to very quickly create a new “Service” that is available system wide. To do this, launch the built in “Automator” tool and select “File” -> “New” to open the template picker. We’re going to create a new “Service” so select that from the dialog and click on “Choose”:

At the top it should default to “Service receives selected” “text” “in” “any application”. If you want to target a specific application, such as Tap Forms in my case, click on “any application” and then “Other…” to find the exact application to target. If you don’t select a specific application, this option will be globally available to you in any application that you open.

Automator historically only supported “AppleScript” as it’s language however recently Apple have added “JavaScript” as a language option. JavaScript is common on the web and increasingly a server side language with node.js. To create a JavaScript block, on the left search box type in “Run JavaScript” and drag it to the right. It’ll drop in a default option starting with “function run” that you can use to get started. In this case what we want to do is take the input text and combine it with a URL so that we can quickly get to an order (AliExpress in this example). To make that happen, I use the following code:

function run(input, parameters) { 
    return "https://trade.aliexpress.com/order_detail.htm?order_id=" + input;

What this does is put in the basic AliExpress URL and then adds the “input” to the end of it. In this case the “input” is the text that was selected before activating the service.

Now we’ve got a fully templated URL that we can use to open a web browser and here Automator has us covered with the “Display Webpages” option. Put this into the search field on the left and then drag the “Display Webpages” to the right hand side. Your Automator window should look like this:

The last step is to save your workflow either by going “File” -> “Save” or by hitting “Command+S” to save it. It’ll prompt you for a name to “Save service as:” and will automatically put the file in your “Services” folder at ~/Library/Services.

Now when you go to you open your application, highlight the text and right click there should be a new option at the bottom (it might also be in a “Services” menu if you have a lot of services enabled):

You can then click this and it will open up your web browser to the URL that we generated via the JavaScript. I also have another service in this example called “Track with 17track” that I use to quickly take a shipping tracking number and plug it into 17track which looks like this:

function run(input, parameters) {
    return "http://www.17track.net/en/track?nums=" + input;

The process is the same to set this up, relatively straight forward and opens up 17track with tracking number as the highlighted text.

This enables me to relatively quickly go from a Tap Forms 5 record over to either AliExpress or 17track to review the data in those particular services.

No comments

No Comments

Leave a comment

%d bloggers like this: