Created
April 11, 2012 20:29
-
-
Save eager/2362276 to your computer and use it in GitHub Desktop.
Example ThisService script using node and LMGTFY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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