-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoom.js
More file actions
146 lines (119 loc) · 3.7 KB
/
zoom.js
File metadata and controls
146 lines (119 loc) · 3.7 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Prefer to take configuration from Alfred Environment Variable
// Set here if you can't or don't want to go through the trouble of configuring
var OrgURL = "zoommtg://yourOrg.zoom.us/";
// ----------------------------------------------------------
ObjC.import('stdlib');
var baseURL = $.getenv('zoomURL') ? $.getenv('zoomURL') : OrgURL;
var app = Application.currentApplication();
app.includeStandardAdditions = true;
function parseMeetingID(text) {
regex = /https:\/\/[a-z0-9.\/]*j\/([0-9].+)/;
regex2 = /([0-9].+)/;
match = regex.exec(text);
if (match !== null) {
return (match[1]);
}
else {
match = regex2.exec(text);
if (match !== null) {
return (match[1]);
}
else {
return "";
}
}
}
function timeStep(startRangeMin, startRangeMax) {
var outlook = Application("Microsoft Outlook");
var calendar = outlook.calendars[1];
var today = new Date();
var plusMinutes = new Date();
var minusMinutes = new Date();
plusMinutes.setMinutes(today.getMinutes() + startRangeMax);
minusMinutes.setMinutes(today.getMinutes() - startRangeMin);
var events = calendar.calendarEvents.whose({
_and: [{
"startTime": {
_greaterThan: minusMinutes
}
},
{
"startTime": {
_lessThan: plusMinutes
}
}
]
});
return (events);
}
function meetingIDFromEvent(event) {
var locationID = parseMeetingID(event.location());
var bodyID = parseMeetingID(event.plainTextContent());
var outputID = "";
// prefer body for source of truth
if (bodyID != "") {
outputID = bodyID;
} else if (locationID != "") {
outputID = locationID;
}
return bodyID;
}
function openZoomMeeting(meetingID) {
if (meetingID != "") {
var uri = baseURL + "join?action=join&confno=" + meetingID;
app.openLocation(uri);
} else {
app.displayDialog("No meeting found");
}
}
function fromOutlook() {
//Prefer earliest meeting, but be prepared to join one that you're incredibly late (or early) for
var events = timeStep(5, 5);
if (events.length == 0) {
events = timeStep(10, 10);
if (events.length == 0) {
events = timeStep(15, 15);
if (events.length == 0) {
events = timeStep(30, 30);
}
if (events.length == 0) {
events = timeStep(45, 45);
}
}
}
if (events.length > 0) {
if (events.length == 1) {
app.displayDialog("Opening meeting for: '" + events[0].subject() + "'");
openZoomMeeting(meetingIDFromEvent(events[0]));
}
if (events.length > 1) {
var event;
var subjects = events().map(m => m.subject());
var subject = app.chooseFromList(subjects, {
withPrompt: "Multiple meetings found, select one:",
defaultItems: subjects[0]
});
if (subject == "") {
app.displayDialog("User cancelled");
return;
}
for (i = 0; i < events().length; i++) {
if (events[i].subject() == subject) {
event = events[i];
}
}
app.displayDialog("Opening meeting for: '" + event.subject() + "'");
openZoomMeeting(meetingIDFromEvent(event));
}
} else {
app.displayDialog("No meeting found");
}
}
function run(argv) {
if (argv.length > 0) {
var query = argv[0];
openZoomMeeting(parseMeetingID(query));
} else {
fromOutlook();
}
}