-
Notifications
You must be signed in to change notification settings - Fork 3
/
jxa.js
39 lines (31 loc) · 934 Bytes
/
jxa.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
'use strict';
function write(str) {
$.NSFileHandle.fileHandleWithStandardOutput.writeData($(JSON.stringify(str)).dataUsingEncoding($.NSUTF8StringEncoding));
}
function run([id]) {
const chrome = Application(id);
if (!chrome.running()) {
const appName = id.split('.').slice(2).map(str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`).join(' ');
write({
appNotRunning: true,
message: `Tried to get tabs of ${appName}, but ${appName} is currently not running.`
});
return;
}
const tabs = [];
for (const [windowIndex, window] of chrome.windows().entries()) {
const activeTabIndex = window.activeTabIndex() - 1;
const windowVisible = window.visible();
for (const [tabIndex, tab] of window.tabs().entries()) {
tabs.push({
windowIndex,
windowVisible,
url: tab.url(),
title: tab.title(),
active: activeTabIndex === tabIndex,
loading: tab.loading()
});
}
}
write(tabs);
}