Created
June 13, 2012 05:22
-
-
Save keverw/2922027 to your computer and use it in GitHub Desktop.
Mac say, Have your JavaScript Node.js app make your Mac speak.
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
global.escapeshell = function(cmd) { //http://stackoverflow.com/a/7685469 | |
return '"'+cmd.replace(/(["\s'$`\\])/g,'\\$1')+'"'; | |
}; | |
global.say = function(string) | |
{ | |
var os = require('os'); | |
if (os.type() == 'Darwin') | |
{ | |
var exec = require('child_process').exec; | |
exec("say " + escapeshell(string), function(error, stdout, stderr) | |
{ | |
console.log(stderr); | |
}); | |
} | |
} | |
say("Hello, Mac user!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment