auto-launch
Version:
Launch node applications or executables at login (Mac, Windows, and Linux)
68 lines (61 loc) • 2.85 kB
JavaScript
var applescript, fileBasedUtilities, untildify,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
applescript = require('applescript');
untildify = require('untildify');
fileBasedUtilities = require('./fileBasedUtilities');
module.exports = {
/* Public */
enable: function(arg) {
var appName, appPath, data, isHiddenOnLaunch, isHiddenValue, mac, programArguments, programArgumentsSection, properties;
appName = arg.appName, appPath = arg.appPath, isHiddenOnLaunch = arg.isHiddenOnLaunch, mac = arg.mac;
if (mac.useLaunchAgent) {
programArguments = [appPath];
if (isHiddenOnLaunch) {
programArguments.push('--hidden');
}
programArgumentsSection = programArguments.map(function(argument) {
return " <string>" + argument + "</string>";
}).join('\n');
data = ""1.0\" encoding=\"UTF-8\"?> xml version=\\n = 0;
});
},
/* Private */
execApplescriptCommand: function(commandSuffix) {
return new Promise(function(resolve, reject) {
return applescript.execString("tell application \"System Events\" to " + commandSuffix, function(err, result) {
if (err != null) {
return reject(err);
}
return resolve(result);
});
});
},
getDirectory: function() {
return untildify('~/Library/LaunchAgents/');
},
getFilePath: function(appName) {
return "" + (this.getDirectory()) + appName + ".plist";
}
};