1 | var Promise, applescript, tellTo;
|
2 |
|
3 | applescript = require('applescript');
|
4 |
|
5 | Promise = require('es6-promise').Promise;
|
6 |
|
7 | tellTo = 'tell application "System Events" to ';
|
8 |
|
9 | module.exports = {
|
10 | enable: function(opts) {
|
11 | return new Promise(function(resolve, reject) {
|
12 | var command, isHidden, properties;
|
13 | isHidden = opts.isHiddenOnLaunch ? 'true' : 'false';
|
14 | properties = "{path:\"" + opts.appPath + "\", hidden:" + isHidden + ", name:\"" + opts.appName + "\"}";
|
15 | command = tellTo + " make login item at end with properties " + properties;
|
16 | return applescript.execString(command, function(err) {
|
17 | if (err != null) {
|
18 | return reject(err);
|
19 | }
|
20 | return resolve();
|
21 | });
|
22 | });
|
23 | },
|
24 | disable: function(opts) {
|
25 | return new Promise(function(resolve, reject) {
|
26 | var command;
|
27 | command = tellTo + ("delete login item \"" + opts.appName + "\"");
|
28 | return applescript.execString(command, function(err) {
|
29 | if (err != null) {
|
30 | return reject(err);
|
31 | }
|
32 | return resolve();
|
33 | });
|
34 | });
|
35 | },
|
36 | isEnabled: function(opts) {
|
37 | return new Promise(function(resolve, reject) {
|
38 | var command;
|
39 | command = tellTo + "get the name of every login item";
|
40 | return applescript.execString(command, function(err, loginItems) {
|
41 | var isPresent;
|
42 | if (err != null) {
|
43 | return reject(err);
|
44 | }
|
45 | isPresent = loginItems != null ? loginItems.indexOf(opts.appName) : void 0;
|
46 | return resolve((isPresent != null) && isPresent !== -1);
|
47 | });
|
48 | });
|
49 | }
|
50 | };
|