1 |
|
2 | var applescript = require('applescript');
|
3 |
|
4 | exports.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 |
|
14 | exports.say = function(text, voice) {
|
15 | var tmp = { text:text };
|
16 | tmp.text.split('"').join("'");
|
17 | var script = 'say "'+text+'"';
|
18 | if (voice) {
|
19 | script += ' using "'+voice+'"'
|
20 | };
|
21 | exports.runScript(script);
|
22 | };
|
23 |
|
24 | exports.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 |
|
38 | exports.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 |
|
47 | exports.openDialog = function(title, text, input, buttons, icon, timeout, callback) {
|
48 | var tmp = { script:'', text:text };
|
49 |
|
50 |
|
51 | };
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
\ | No newline at end of file |