-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_listing.js
More file actions
47 lines (42 loc) · 1.02 KB
/
Copy pathwindow_listing.js
File metadata and controls
47 lines (42 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
module.exports = (function(){
let exec = require('child_process').exec;
let path = require('path');
let bashInterpreter = require('bash-interpreter');
let svc = {};
svc.getAll = getAll;
return svc;
function getAll(uid){
var cmd = [];
if (uid){
cmd.push('launchctl asuser ' + uid + " ");
}
cmd.push('"' + path.resolve(__dirname, "bin/WindowList") + '"');
return execute(cmd.join('')).then((output)=>{
return bashInterpreter.parse(output, {
headers: {
"PID": "pid",
"WindowID": "windowId",
"Title": "windowTitle"
}
});
});
}
function execute(cmd) {
return new Promise((resolve, reject)=>{
var options = {
cwd: path.resolve(process.cwd()),
encoding: 'utf8',
maxBuffer: 2*1024*1024
};
var output;
exec(cmd, options, function(err, stdout, stderr){
if (!err){
resolve(stdout);
} else {
reject(new Error(err));
}
});
});
}
})();