Save this as glucky-markdown.rb somewhere...
#!/usr/bin/env ruby
require 'uri'
require 'json'
require 'net/http'
def goog(msg)
uri=URI.parse "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%s"\
% URI.escape(msg)
req = Net::HTTP::Get.new(uri.request_uri)
http = Net::HTTP.new(uri.host)
http.read_timeout = 5
http.open_timeout = 5
res = http.start { |server|
server.request(req)
}
JSON.parse(res.body)['responseData']['results'][0]['url']
end
text = ARGV[0]
term = ARGV[1]
puts "[#{text}](#{goog(term)})"
Now, create a TextExpander Shell Script snippet with the following...
#!/bin/bash
source ~/.bashrc; ~/Scripts/glucky-markdown.rb "%filltext:name=Link Text:default=Link Text%" "%filltext:name=Search Text:default=Search Term%"
I use the source ~/.bashrc
to get rbenv, and you'll need to update the path to point to your copy of that script.