Although previously described reduction algorithm links through "Avtomator"From a technical point of view, works flawlessly, in practice, it can cause problems. For example, Facebook social network often does not pass references to goo.gl, considering them to be potentially dangerous. So we had to be puzzled "Plan B" in which the main role is played by another web service - Bitly.com.
With this service problems on the "Facebook" is not there, but in a "plan B" entered an important point - the compulsory registration on Bitly.com. On the one hand, it's a bit more fuss, but thanks to this you have the advantage of: all cut across service "Avtomatora" links will be stored under your account on Bitly. Besides Bitly, unlike Goo.gl, supports native "sokraschalku» Facebook - on.fb.me. ;)
By registering, go to the page bitly.com/a/settings/advanced. At the bottom, click the link Show legacy API key and check for themselves the text box Login - the content you need quickly.
Now you can create service "Avtomatore". In finished form it looks like this:
As you can see, this is a console bash-script that takes the processing of the selected text in the text (web link) and replaces it with a shorter web address (all defined in the "header" of the process). Here is the full text:
encodedURL = $ (echo -n "$ 1" | sed 's / /% 20 / g;! S / /% 21 / g; s / "/% 22 / g; s / # /% 23 / g; s / $ /% 24 / g; s / & /% 26 / g; s //% 27 / g; s / (/% 28 / g; s /) /% 29 / g; s /: /% 3A / g ') userID =userPASS = if [[$ encodedURL = http *]!]; then encodedURL = " http://$encodedURL" fi accessToken = $ (curl " https://api-ssl.bitly.com/oauth/access_token" --request "POST" --user "$ userID: $ userPASS") curl " https://api-ssl.bitly.com/v3/shorten" --data "access_token = $ {accessToken}" --data "format = txt" --data "longUrl = $ encodedURL"
All code can be divided into three parts:
- First, we set three variables: the incoming Web link (with the ASCII-conversion), as well as your Bitly-ID (remember the text box Login, Which was discussed just above?) And Bitly-password. Do not forget to instead and
substitute their values. - Further, using the variable with the ID and password, through the security system Bitly.com obtain the so-called security token.
- Finally, using the access token generated by console command curl send the original web address and get its shortened version, which substitutes the Automator in the text.
It now remains only to keep the service under the name convenient for you - and test the results in a text field.
P. S. In the comments to the previous article on the reduction of links through Automator called Universal Web Service Shrt.org.uaWhich greatly simplifies the algorithm and allows you to work with any of dozens of web sokraschalok without any login and authentication. However, since this project is supported by enthusiasts, in his work things go wrong - annoying when you want to quickly shorten the link see a message about the unavailability of the service.
P. P. S. That is what he Automator and useful Mac users, you can always learn from the material on "MakRadare".
Posted: Reader Eugene Stepanishev passed have no inaccuracies in the foregoing script code, and offered his own, more concise and versatile option. Eugene the script to suit everyone who is facing in dealing with web links containing a non-Latin symbols (for example, addresses with search queries in Russian, references to articles in the Russian "Wikipedia", and so on. d.). Thank you very much for your participation.