Skip to content

Instantly share code, notes, and snippets.

@eager
Created April 11, 2012 20:29
Show Gist options
  • Save eager/2362276 to your computer and use it in GitHub Desktop.
Save eager/2362276 to your computer and use it in GitHub Desktop.
Example ThisService script using node and LMGTFY
#!/usr/local/bin/node
// Unfortunately, /usr/bin/env node doesn’t work if node is in /usr/local/bin
var spawn = require('child_process').spawn,
textutil = spawn('textutil', ['-stdin', '-stdout', '-format', 'html', '-convert', 'rtf'])
pbcopy = spawn('pbcopy')
textutil.stdout.pipe(pbcopy.stdin)
process.stdin.resume()
process.stdin.setEncoding('utf8')
var query = "",
LMGTFY = "http://lmgtfy.com/?q="
process.stdin.on('data', function (chunk) {
query += chunk
})
process.stdin.on('end', function () {
textutil.stdin.write("<a href='" + LMGTFY + query + "'>" + query + "</a>")
textutil.stdin.end()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment