1

 Acorta con Bit.ly nativamente en Snow Leopard

Una de las mejores ideas que pudieron tener en Apple con la inclusión de los servicios en Mac OS X Snow Leopard desde Automator, brindándonos un sencillo acceso al menú contextual de todas las aplicaciones con diversas acciones interesantes.

La de hoy es muy sencilla de hacer y quiere una única cosa: que tengamos cuenta en Bit.ly. Por lo demás todo consiste en estos pasos:

  1. Abre Automator.
  2. Elige crear un nuevo servicio.
  3. Añade la acción “Ejecutar AppleScript”.
  4. Copia el código que dejo tras el salto modificando tu login y tu API_KEY.

¡Hecho! Ahora podrás acortar enlaces con Bit.ly desde el menú contextual e irán directos a tu portapapeles.

Fuente | Zettt

on run {input, parameters}
	set login to "YourLogin"
	set apiKey to "YourAPIKey"

	-- this one makes it easier to handle the input
	-- as it transforms the input into a (fixed) text object
	set inputURL to input as string

	-- error handling
	if inputURL does not start with "http" then
		-- we don't have an http in front so let's check if
		-- we find anything useful in the inputURL
		if inputURL begins with "www" then
			set inputURL to "http://" & inputURL
		else
			set inputURL to check_clipboard(inputURL)
		end if
		-- there's still nothing useful so let's break
	else
		display dialog "This action needs a valid http address either to be on the clipboard or selected!"
		return

	end if

	-- shorten the url
	set bitlyCommand to "http://api.bit.ly/shorten?version=2.0.1&longUrl=" & inputURL & "&login=" & login & "&apiKey=" & apiKey & ""
	set shortURL to do shell script "curl " & quoted form of bitlyCommand & " | grep shortUrl | awk '{print $2}' | sed 's/[",]//g'"

	-- set clipboard contents to the new short url
	-- and paste it into the textfield
	set the clipboard to shortURL as text
	tell application "System Events"
		keystroke "v" using command down
	end tell

	return input
end run

-- Check if there is a link on the clipboard already
on check_clipboard(inputURL)
	set clipboard_contents to the clipboard as text
	if clipboard_contents contains "http"then
		set inputURL to clipboard_contents
	end if
	return inputURL
end check_clipboard

Noticias Relacionadas

Comenta esta noticia
1 comentario
Puntua esta noticia
Me gustaNo me gusta (sin puntuar)
Categoría: Apple, Mac OS X, Trucos

1 Comentario

  1. raziel dice:

    ok lo hice y aparece el nombre que le puse pero no se donde quedan los enlaces ya acortados pueden decirme.?? on en su defecto como lo desinstalo

    Tu valoración: Thumb up 0 Thumb down 0

¿Te ha parecido interesante la noticia? ¡Déjanos tu comentario!

Publicidad
Publicidad