-
Notifications
You must be signed in to change notification settings - Fork 1
/
announce-zoom-chat-messages.js
111 lines (97 loc) · 3.33 KB
/
announce-zoom-chat-messages.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
currApp = Application.currentApplication()
currApp.includeStandardAdditions = true
SE = Application('System Events')
SE.includeStandardAdditions = true
past_length = undefined
dormant = false
ZoomApp = SE.applicationProcesses.byName("zoom.us")
function is_meeting_ongoing() {
// the window "Zoom meeting" isn't reported if it's in a non-active Mission Control "Space"
// so let's check whether Zoom's Window menu contains a "Zoom Meeting" menuItem
try {
ZoomApp.menuBars()[0].menuBarItems.byName("Window").menus.byName("Window").menuItems.byName("Zoom Meeting")()
} catch (error) {
return false
}
return true
}
function get_chat_length(){
// returns the number of lines in chat (including the name lines!)
// get content of detached chat window
zwc = ZoomApp.windows.whose({ name: { _contains: 'Chat' } })
if (zwc.length == 1) {
// there is a chat window
zwcs = zwc.splitterGroups.at(0)
zwcss = zwcs.scrollAreas.at(0)
zwcsst = zwcss.tables.at(0)
zwcsstr = zwcsst.rows
return zwcsstr.length
}
// get content of attached chat window
zwc2 = ZoomApp.windows.whose({ name: { _contains: 'Zoom Meeting' } })
sidepanel = zwc2.splitterGroups[0]
chat_embedded = sidepanel.splitterGroups[0]
if (chat_embedded()[0] == null) {
// the chat panel is not where it should
return null
}
text_rows = chat_embedded.scrollAreas[0].tables[0].rows
return text_rows.length
}
function idle(){
if (! is_meeting_ongoing()) {
if (! dormant) {
// let's warn and go dormant
past_length = undefined
dormant = true
currApp.beep(1)
currApp.displayNotification("Waiting for any new meeting...",
{withTitle:"No Zoom meeting detected"})
}
return 30
}
dormant = false
try {
length = get_chat_length()
} catch (error) {
SE.displayAlert("Unable to get the chat length", {
message: "Please check that the script is allowed in System Preferences " +
"- Security & Privacy - Privacy - Accessibility.\n\nYou might need to " +
"UNCHECK its checkbox and RE-CHECK it again.",
as: "critical",
buttons: ["Show me where"],
defaultButton: "Show me where"
}
)
SP = Application("System Preferences")
SP.panes.byId("com.apple.preference.security").anchors.byName("Privacy_Accessibility").reveal()
SP.activate()
ObjC.import('stdlib')
$.exit(1)
}
if (length == null) {
currApp.beep(1)
currApp.displayNotification("Please open it to detect changes",
{withTitle:"The chat window seems to be closed!"})
past_length = undefined
return 5
} else {
if (typeof past_length == 'undefined'){
currApp.displayNotification("Currently contains " + length + " lines",
{withTitle:"Tracking chat..."})
} else if (length != past_length) {
//content_new = content.slice(past_length)
//text_new_asciipos = text_new.search(/\w/)
//text_new_ascii = text_new.slice(text_new_asciipos)
currApp.beep(3)
currApp.displayNotification("",
{withTitle:"New text in chat"})
}
past_length = length
}
return 1
}
function quit(){
currApp.displayNotification("",{withTitle:"Chat is no longer tracked"})
return true
}