One of the tasks that almost everyone repeats daily is the URL shortening. Whenever we want to post a link in our twitter/facebook status, we usually follow the steps below:
1) Select and copy the really long URL to the clipboard (Ctrl+C),
2) Paste it in a shortening service's form,
3) Hit the submit button,
4) Wait for the service to return the short URL,
5) Copy the short URL,
6) Paste the short URL into our social networking site.
The job that I will create today, will remove steps 2, 3, 4 and 5 from the equation. All you will have to do in order to paste a short URL instead of a long one, is:
1) Select and copy the really long URL to the clipboard (Ctrl+C),
2) Hit a specific HotKey (i.e Ctrl+Shift+V) and the short URL will be pasted instead of the long one.
So, let's get started. The URL shortening service that I will use is http://is.gd. It does not only provide the shorter URLs out there, but it also has a very simple submission form for the purpose of this tutorial.
The first thing that we need to do, is visit the service's webpage:

Now, we need to examine its source code so that we can understand how the form works. To do that, we just right click anywhere in the page and select "View Source" in Internet Explorer or "View Page Source" in Mozilla Firefox (alternatively in Firefox you can just hit the Ctrl+U keystroke combination). The part of the web page source that we are interested in is shown in the screenshot below:

The path that is mentioned in the form's action property is the URL that we will fill in the "Download from Web" action.
The method will be selected by the action's drop down menu.
In this specific case, the form has only one input, so the only POST parameter that needs to be declared is the URL parameter. In the URL parameter we will pass the "long URL" and the site will generate a short URL for us.
Before we start creating our job, we need to define the exact steps of our process. Since the URL will already be in the clipboard:
1) We need to retrieve the URL from the clipboard and save it to a variable,
2) Submit the "long URL" to the shortening service,
3) Parse the text that the webpage returns to isolate the short URL
4) Store the short URL to the clipboard
5) Send a Ctrl+V keystroke combination to paste the short URL that is saved on the clipboard
All of the steps above are pretty straightforward and can be implemented by a single action. The corresponding actions are shown below:
1) "Get Clipboard Text" (under "Clipboard" category)
2) "Download from Web" (under "Web" category)
3) "Parse Text" (under "Text Actions" category)
4) "Set Clipboard Text" (under "Clipboard" category)
5) "Send Keys" (under "Mouse and Keyboard" category)
Since the "Download from Web" action is analyzed above, the only tricky part now is to isolate the short URL in the result page:

And if we look at the source code:

we can easily understand how the regular expression should look like. Since it is out of the scope of the specific article to explain how to build the regular expression, I will just give a screenshot of Expresso, the application that I'm using to build my regular expressions:

Our job should look like this now:

The final thing that we need to do, is create a trigger that will fire the job. After the job is saved, right click on it in the console window and select "Edit Triggers".

Then, follow the steps that are shown in the screenshots below:



Hit OK and we are done!
In order to test your newly created job now, select a very long URL, hit Ctrl+C to copy it to the clipboard, place your cursor in your twitter/facebook status and press Ctrl+Shift+V. After a couple of seconds the short URL will be pasted instead of the original long one.
Post new comment