concepto-bridge
Version:
Concepto DSL - Live Mode Bridge
66 lines (56 loc) • 1.76 kB
JavaScript
// apple helper module
var applescript = require('applescript');
exports.runScript = function(script, onSuccess, onError) {
applescript.execString(script, function(err, data) {
if (err && onError) {
onError(err);
} else if (onSuccess) {
onSuccess(data);
}
});
};
exports.say = function(text, voice) {
var tmp = { text:text };
tmp.text.split('"').join("'"); // replace " with '.
var script = 'say "'+text+'"';
if (voice) {
script += ' using "'+voice+'"'
};
exports.runScript(script);
};
exports.isAppOpen = function(app, success, error) {
var the_script = 'tell application "System Events"\n';
the_script += ' if(get name of processes contains "'+app+'") then\n';
the_script += ' return true\n';
the_script += ' else\n';
the_script += ' return false\n';
the_script += ' end if\n';
the_script += 'end tell\n';
exports.runScript(the_script, function(resp){
if (resp=='true'||resp=='false') resp=eval(resp);
success(resp);
}, error);
};
exports.openApp = function(app, success, error) {
var the_script = 'try\n';
the_script += 'tell application "'+app+'"\n';
the_script += ' launch\n';
the_script += 'end tell\n';
the_script += 'end try\n';
exports.runScript(the_script, success, error);
};
exports.openDialog = function(title, text, input, buttons, icon, timeout, callback) {
var tmp = { script:'', text:text };
};
// TESTS
// examples
/*
exports.say('Hola amigos mios! Espero que lo esten pasando bien! Un gran abrazo navideño.');
// Very basic AppleScript command. Returns the song name of each
// currently selected track in iTunes as an 'Array' of 'String's.
var script = ;
exports.runScript('tell application "iTunes" to get name of selection',
function(resp) {
console.log(resp);
}
);*/