[Script] Let me Google that for you

Sharing and discussing custom actions for LaunchBar
Post Reply
ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

[Script] Let me Google that for you

Post by ptujec » Thu Jun 25, 2009 4:25 pm

http://lmgtfy.com is a really fun way to share things you found on Google.com.

Here is a quick and easy script which returns a shortened url for lmgtfy.com. It also copies the shorturl to your clipboard.

Code: Select all

-- by @ptujec 25/06/09
--
-- perl url encode routine - handles IDN and UTF-8 Chars)
-- by @cometbus
-- (→ see http://twitter.com/cometbus/status/2023559489)
--
-- Insert a searchquery (musst not contain spaces!). You will get a shortURL for lmgtfy.com back.
-------------------------------------------

on handle_string(searchquery)
   
   set longURL to "http://lmgtfy.com/?q=" & searchquery
   set shortURL to shortenURL(longURL)
   set the clipboard to shortURL as text
   
   tell application "LaunchBar" to set selection as text to shortURL
   
end handle_string

-------------------------------------------

on shortenURL(longURL)
   set escapedURL to urlencode(longURL)
   set cmd to "curl 'http://is.gd/api.php?longurl=" & escapedURL & "'"
   set shortURL to do shell script cmd
   return shortURL
end shortenURL

-------------------------------------------

on urlencode(theText)
   set _scpt to "perl -MURI::Escape -e \"print uri_escape('" & theText & "');\""
   return do shell script _scpt
end urlencode

-------------------------------------------


Known issues:
- No "" accepted in query
Last edited by ptujec on Thu Jun 25, 2009 7:02 pm, edited 1 time in total.

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Re: [Scritp] Let me Google that for you

Post by sjk » Thu Jun 25, 2009 7:00 pm

Typo: [Scritp]

Are you posting on an iPhone? :)

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: [Scritp] Let me Google that for you

Post by ptujec » Thu Jun 25, 2009 7:03 pm

sjk wrote:Typo: [Scritp]

Are you posting on an iPhone? :)


No I'm just bad at typing ;)

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Re: [Scritp] Let me Google that for you

Post by sjk » Thu Jun 25, 2009 11:16 pm

ptujec wrote:No I'm just bad at typing ;)

And I can't control my proofreading. :)

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: [Scritp] Let me Google that for you

Post by ptujec » Thu Jun 25, 2009 11:19 pm

sjk wrote:
ptujec wrote:No I'm just bad at typing ;)

And I can't control my proofreading. :)

And I'm actually very happy about that. Maybe I should send posts to you before I publish them ;)

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Re: [Scritp] Let me Google that for you

Post by sjk » Fri Jun 26, 2009 5:42 am

ptujec wrote:And I'm actually very happy about that.

Glad that affliction I'm cursed with can make someone happy.

Maybe I should send posts to you before I publish them ;)

Only for a fee will I guarantee, but my curse may give it to you for free. :)

Forumposter
Posts: 18
Joined: Wed Jul 29, 2009 7:56 pm

Re: [Script] Let me Google that for you

Post by Forumposter » Mon Aug 03, 2009 5:49 pm

Code: Select all

Known issues:
- No "" accepted in query


Any chance you can fix that?

Post Reply