-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-state.js
37 lines (30 loc) · 944 Bytes
/
app-state.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
// noinspection JSUnresolvedFunction,JSUnresolvedVariable
function getKmVariable(k) {
const kme = Application("Keyboard Maestro Engine");
return kme.getvariable(k);
}
window.main = ([ appName ]) => {
console.log("app name:", getKmVariable("appName"))
if (!appName) {
console.log("Usage: app-state appName");
console.log("Example: app-state Safari");
return;
}
if (!Application(appName).running()) {
console.log("APP_NOT_RUNNING");
return;
}
const proc = Application("System Events").processes.byName(appName);
if (proc.windows.length === 0) {
console.log( "APP_RUNNING_NO_WINDOWS");
return;
}
if (proc.frontmost()) {
console.log( "APP_RUNNING_FRONTMOST");
return;
}
// with Ventura stage manager, it seems this is all we can find out;
// proc.miniaturized/visible/zoomed won't tell us if the app has an open window on the
// screen or not
console.log("APP_RUNNING");
}