UNPKG

1.76 kBJavaScriptView Raw
1// apple helper module
2var applescript = require('applescript');
3
4exports.runScript = function(script, onSuccess, onError) {
5 applescript.execString(script, function(err, data) {
6 if (err && onError) {
7 onError(err);
8 } else if (onSuccess) {
9 onSuccess(data);
10 }
11 });
12};
13
14exports.say = function(text, voice) {
15 var tmp = { text:text };
16 tmp.text.split('"').join("'"); // replace " with '.
17 var script = 'say "'+text+'"';
18 if (voice) {
19 script += ' using "'+voice+'"'
20 };
21 exports.runScript(script);
22};
23
24exports.isAppOpen = function(app, success, error) {
25 var the_script = 'tell application "System Events"\n';
26 the_script += ' if(get name of processes contains "'+app+'") then\n';
27 the_script += ' return true\n';
28 the_script += ' else\n';
29 the_script += ' return false\n';
30 the_script += ' end if\n';
31 the_script += 'end tell\n';
32 exports.runScript(the_script, function(resp){
33 if (resp=='true'||resp=='false') resp=eval(resp);
34 success(resp);
35 }, error);
36};
37
38exports.openApp = function(app, success, error) {
39 var the_script = 'try\n';
40 the_script += 'tell application "'+app+'"\n';
41 the_script += ' launch\n';
42 the_script += 'end tell\n';
43 the_script += 'end try\n';
44 exports.runScript(the_script, success, error);
45};
46
47exports.openDialog = function(title, text, input, buttons, icon, timeout, callback) {
48 var tmp = { script:'', text:text };
49
50
51};
52
53// TESTS
54// examples
55/*
56exports.say('Hola amigos mios! Espero que lo esten pasando bien! Un gran abrazo navideño.');
57
58// Very basic AppleScript command. Returns the song name of each
59// currently selected track in iTunes as an 'Array' of 'String's.
60var script = ;
61
62exports.runScript('tell application "iTunes" to get name of selection',
63 function(resp) {
64 console.log(resp);
65 }
66);*/
\No newline at end of file