Skip to content

Instantly share code, notes, and snippets.

@keverw
Created June 13, 2012 05:22
Show Gist options
  • Save keverw/2922027 to your computer and use it in GitHub Desktop.
Save keverw/2922027 to your computer and use it in GitHub Desktop.
Mac say, Have your JavaScript Node.js app make your Mac speak.
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