J-D Strong Consulting, Inc. - Business Technology Solutions
J-D Strong Consulting, Inc.
Search

HOURS

Weekends and evenings by arrangement, otherwise a $200 after-hours fee applies.

CONTACT US

Kerio Mail Server

DriveSavers - Save on Professional Data Recovery Services

 
Submitted by Jack-Daniyel Strong on Fri, 04/04/2008 - 10:33pm.

If you have not checked out SmileOnMyMac's Text Expander, you really should. Whether you enable just the TidBITS AutoCorrect Dictionary for TextExpander Snippet or you use it to manage email signatures, common phrases, corrections, instruction blurbs or more. One of the cool features is a snippet from David Smalley to put TinyURL capabilities at your fingertips. While this is a great start, his script is too involved to make it fast enough to replace the text and let you carry on with your typing.

I've created two options, both with a faster, sleeker call to TinyURL's core API and a little error checking to save you from pasting in a huge XML error. Open up TextExpander and add a new Snippet, select Applescript, then paste one of the two following options in. Use the abbreviation tinyurl. Close TextExpander, copy a URL to the clipboard and type tinyurl. Voila!

Option 1: Error checking and a kill dialog

set the ClipURL to (the clipboard as string)

set q to display dialog ClipURL with title ¬
	"TinyURL Link" buttons {"TinyURL", "Wrong URL"} ¬
	default button 2 giving up after 2

ignoring case
	if button returned of q is "Wrong URL" or ¬
		((characters 1 through 4 of ClipURL as string) is not "http") then
		return "Malformed URL."
	else
		set curlCMD to ¬
			"curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & ClipURL & "\""
		
		-- Run the script and get the result:
		set tinyURL to (do shell script curlCMD)
		
		return tinyURL
	end if
end ignoring

Option 2: Just Error checking

set the ClipURL to (the clipboard as string)

ignoring case
	if ((characters 1 through 4 of ClipURL as string) is not "http") then
		return "Malformed URL."
	else
		set curlCMD to ¬
			"curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & ClipURL & "\""
		
		-- Run the script and get the result:
		set tinyURL to (do shell script curlCMD)
		
		return tinyURL
	end if
end ignoring
  © 2003-2008 >   J-D Strong Consulting, Inc. > Post Office Box 4162, Spokane, WA 99220 > 509.879.1831