I often have to insert a very long web addresses, for example, in the captions for pictures on Facebook or messages to friends on Skype. Although the character limit in these cases, I do not have long links look ugly and can "break" the appearance of the text. Better than these "sausages" to cut: Select the long link, clicked the right mouse button, select the command in the context menu cut link - and replaced the long URL short. And it does not need any special tools - with the help of "Avtomatora" make such sokraschalku yourself easy.
How it should work
The input of the service "Avtomatora" supplied text fragment - Dedicated text long web link. The first act of sending this link service Google links reduction (goo.gl) - it uses special console command, described in the manual for Google Developers (cm. an example of a team curl). In response to the query we get a set of three pairs of string values. In the second pair is stored already prepared a short link.
After that, from the resulting data set we keep out all the excess, leaving only two references - a short and original length. We use short-an AppleScript script to output we only had a short link, which automatically and will be inserted into the original text instead of a dedicated long before the web address.
How it looks in reality
Create a "Avtomatore" new service. In the title, set the parameters so that the service received "selected Text (text) in any application (any application)ยป. It is very important that the setting was enabled Output data replaces the selected text (Output replaces selected text) - the only way to replace the selected service can link you to a shorter URL.
Under the heading, drag from the action library Run AppleScript (Run AppleScript) and enter in the following code (which it will send the request to goo.gl and receive a reply from him):
on run {input, parameters} set result to (do shell script "curl https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application / json' -d '{ "longUrl": "" & input & ""}' ") --Podrobnosti at: http://goo.gl/KDQv1. return result end run
The second drag from the action library Extract data from text (Extract Data from Text) and in the drop-down list extract select URL-addresses (URLs).
Last activity - another AppleScript-script with this code:
on run {input, parameters} repeat with i in input set shortened to (i as text) exit repeat end repeat return shortened. end run
That statement return shortened
pass the exit shortened link that service will insert into your text instead of a dedicated long before the web address.
Save the service by specifying a name, for example, Shorten the link (Shorten URL)And immediately see whether it operates: type in any text field you want a web address (for example, http://macradar.ru/tips/automator-podschet-obema-teksta-v-lyuboj-mak-programme/), Select it, click on the right mouse button and on the shortcut menu, click Shorten the link (Shorten URL) - a moment to occur required hocus-pocus. :)
update:
Excellent hint given in the comments DmitriyLyalyuev, advising him to use the service shrt.org.ua. Due to the fact that it immediately returns the finished result (shortened link) without any extra data for our case, Create a service "Avtomatora" can greatly simplify - to remove the second and third steps, and the first to enter the following the code:
on run {input, parameters} set result to (do shell script "curl ' http://shrt.org.ua/--?url=" & Input & "& s = goo.gl '") --Podrobnosti at: http://shrt.org.ua return result end run
It also accesses the Goo.gl (although you can use any other sokraschalku specified in the list of supported), but after Shrt.org.ua as a mediator. If that option is also suitable, in you should get a result, that's such a service: