-
Notifications
You must be signed in to change notification settings - Fork 6
/
wintraffic.js
61 lines (49 loc) · 1.49 KB
/
wintraffic.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var fs = require("fs");
var child = require("child_process");
function rand(mod) {
return Math.floor(Math.random() * mod);
}
var apps = fs.readdirSync("/Applications").slice(2);
for (var i = 0; i < apps.length; i++) {
apps[i] = "/Applications/" + apps[i] + "/Contents/MacOS/" + apps[i].replace(/.app/, "");
}
var app = apps[rand(apps.length)];
console.log("[i] chose app:", app);
var width = rand(8000);
var height = rand(6000);
var x = rand(8000);
var y = rand(6000);
var script = `
set theApp to "${app.split("/")[app.split("/").length - 1]}"
set appHeight to ${width}
set appWidth to ${height}
tell application "Finder"
set screenResolution to bounds of window of desktop
end tell
set screenWidth to item 3 of screenResolution
set screenHeight to item 4 of screenResolution
tell application theApp
activate
reopen
set yAxis to (screenHeight - appHeight) / 2 as integer
set xAxis to (screenWidth - appWidth) / 2 as integer
set the bounds of the first window to {xAxis, yAxis, appWidth + xAxis, appHeight + yAxis}
end tell
tell application "System Events"
set position of first window of process theApp to {${x}, ${y}}
end tell
EOF`;
console.log(script);
try {
var proc = child.exec(app);
var res = child.execSync("osascript <<EOF | echo " + script);
setTimeout(function() {
try {
var res = child.execSync("killall '" + app.split("/")[app.split("/").length - 1] + "'");
} catch(e) {
process.exit();
}
}, 4000);
} catch(e) {
console.log("[!] application did not launch", e);
}