/
Teams.ahk
3805 lines (3215 loc) · 144 KB
/
Teams.ahk
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Documentation of Lib dependencies
#Include <People>
#Include <UriDecode>
#Include <Teamsy>
#Include <Clip>
#Include <FindText>
#Include <UIA_Interface>
Teams_Launcher(){
Teamsy("-g")
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_GetVer() { ; NOT WORKING
; Get Client Version information
If Teams_IsNew() {
Loop, Reg, HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\
{
MsgBox % A_LoopRegName
If RegExMatch(A_LoopRegName,"U)^MSTeams_(.*)_",sMatch)
return sMatch1
}
}
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_BackgroundOpenLibrary() {
If GetKeyState("Ctrl") {
Teamsy_Help("cbg")
return
}
sIniFile = %A_ScriptDir%\PowerTools.ini
If !FileExist(sIniFile) {
TrayTipAutoHide("Error!","PowerTools.ini file is missing!",2000,3)
return
}
IniRead, CustomBackgroundsLibrary, %sIniFile%, Teams, TeamsCustomBackgroundsLibrary
If (CustomBackgroundsLibrary != "ERROR")
Run, "%CustomBackgroundsLibrary%"
Else {
Run, notepad.exe %sIniFile%
TrayTipAutoHide("Background Library!","Background Library location is configured in PowerTools.ini Teams->TeamsCustomBackgroundsLibrary parameter.")
}
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_BackgroundGetFolder(doOpen := true){
; BackgroundDir := Teams_BackgroundGetFolder(doOpen := true)
If GetKeyState("Ctrl") {
Teamsy_Help("cbg")
return
}
If Teams_IsNew() { ; Teams New
; https://techcommunity.microsoft.com/t5/microsoft-teams-public-preview/backgrounds/m-p/3782690
EnvGet, LOCALAPPDATA, LOCALAPPDATA
BackgroundDir = %LOCALAPPDATA%\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\Backgrounds\Uploads
} Else { ; Teams Classic
BackgroundDir = %A_AppData%\Microsoft\Teams\Backgrounds\Uploads
}
If !FileExist(BackgroundDir)
FileCreateDir, %BackgroundDir%
If (doOpen)
Run, %BackgroundDir%
return BackgroundDir
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
; -------------------------------------------------------------------------------------------------------------------
Teams_BackgroundImport(srcDir:=""){
; https://techcommunity.microsoft.com/t5/microsoft-teams-public-preview/backgrounds/m-p/3782690
; Default will migrate Classic Client location to New Teams Background location
If GetKeyState("Ctrl") {
Teamsy_Help("bgi")
return
}
If !Teams_IsNew()
{
return
}
If (srcDir = "") { ; prompt user to select directory
srcDir = %A_AppData%\Microsoft\Teams\Backgrounds\Uploads
SelectFolder(srcDir,"Select folder from which to import background images:")
;FileSelectFolder, srcDir , ,0 , Select folder from which to import background images:
If ErrorLevel
return
}
EnvGet, LOCALAPPDATA, LOCALAPPDATA
NewBackgroundDir = %LOCALAPPDATA%\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\Backgrounds\Uploads
If !FileExist(NewBackgroundDir)
FileCreateDir, %NewBackgroundDir%
; Generate array of MD5 checksums for background files
ArrayCount := 0
MD5Array := []
Loop, Files, %NewBackgroundDir%\*
{
If InStr(A_LoopFileName,"_thumb.")
Continue
ArrayCount += 1
MD5Array[ArrayCount] := HashFile(A_LoopFileFullPath,"MD5")
}
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
return
}
BgCount := 0
BgCopiedCount :=0
Loop, Files, %srcDir%\*
{
; Skip files ending with _thumb.
If InStr(A_LoopFileName,"_thumb.")
Continue
BgCount +=1
; Check if file already exist
srcMD5 := HashFile(A_LoopFileFullPath,"MD5")
If HasVal(MD5Array,srcMD5)
Continue
BgCopiedCount +=1
; Generate GUID
GUID := CreateGUID()
GUID := SubStr(GUID,2,-1)
StringLower, GUID, GUID
RegExMatch(A_LoopFileName,"\.([^\.]*$)",FileExt)
FileCopy, %A_LoopFileFullPath%, %NewBackgroundDir%\%GUID%.%FileExt1%
; Save Thumbnail
destThumbFile = %NewBackgroundDir%\%GUID%_thumb.%FileExt1%
srcThumbFile := RegExReplace(A_LoopFileFullPath,"\.*$") . "_thumb." . FileExt1
If FileExist(srcThmbFile) {
FileCopy, %srcThumbFile%, %destThumbFile%
} Else {
; Create Thumbnails using Gdip
pBitmap := Gdip_CreateBitmapFromFile(A_LoopFileFullPath)
pThumbnail := Gdip_GetImageThumbnail(pBitmap, 278, 159)
Gdip_SaveBitmapToFile(pThumbnail, destThumbFile)
}
}
TrayTip Backgrounds imported! , %BgCopiedCount%/%BgCount% backgrounds were copied!
Run, %NewBackgroundDir%
If !(pBitmapt = "") {
Gdip_DisposeImage(pBitmap)
Gdip_DisposeImage(pThumbnail)
}
Gdip_Shutdown(pToken)
; Merge/save BackgroundNames in PowerTools.ini
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_BackgroundName2File(Name:=""){
; Name := Teams_BackgroundFile2Name(File:="",mode:="r")
; If no File input, user will be prompted to select an image file
; If mode is "w" (write) user can change the name value if already existing
If GetKeyState("Ctrl") {
Teamsy_Help("bg")
return
}
; Get Background File
If (Name = "") {
BackgroundDir := Teams_BackgroundGetFolder(false)
FileSelectFile, File, 1, %BackgroundDir%,Select a background image
If ErrorLevel
return
Px := PathX(File)
File := Px.File
File := StrReplace(File, "_thumb.",".") ; in case thumbnail was selected
} Else If (Name ="no") {
File := "No background effect" ; TODO lang
return File
} Else {
If !FileExist("PowerTools.ini") {
PowerTools_ErrDlg("No PowerTools.ini file found!")
return
}
IniRead, TeamsBackgroundNames, PowerTools.ini,Teams,TeamsBackgroundNames
If (TeamsBackgroundNames="ERROR") {
PowerTools_ErrDlg("TeamsBackgroundNames key not found in PowerTools.ini file [Teams] section!")
return
}
JsonObj := Jxon_Load(TeamsBackgroundNames)
For i, bg in JsonObj
{
name_i := bg["name"]
If RegExMatch(name_i,"^" . StrReplace(Name,"*",".*")) {
File := bg["file"]
break
}
}
}
return File
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_MeetingBackgroundSet(File:="") {
WinId := Teams_GetMeetingWindow()
If !WinId ; empty
return
If (File = "") or !InStr(File,".") ; no file name with extension bug Background simple name
File := Teams_BackgroundName2File(File)
If (File = "")
return
WinGet, curWinId, ID, A
WinActivate, ahk_id %WinId%
UIA := UIA_Interface()
TeamsEl := UIA.ElementFromHandle(WinId)
; Check if rail pane already opened - if yes close it
El := TeamsEl.FindFirstBy("AutomationId=rail-header-close-button")
El.Click()
TeamsEl.WaitElementNotExist("AutomationId=rail-header-close-button")
El.Click()
; Click on More -> Video Effects
El := TeamsEl.FindFirstBy("AutomationId=callingButtons-showMoreBtn")
El.Click()
El := TeamsEl.WaitElementExist("AutomationId=video-effects-and-avatar-button",,,,1000)
El.Click()
Name := Teams_GetLangName("ShowAllBackgrounds","Show all background effects")
El := TeamsEl.WaitElementExistByName(Name,,1,false,1000) ; 1 match mode start with
If !El {
;error notification
PowerTools_ErrDlg("UIA Element 'Show all backgrounds' not found!")
WinActivate, ahk_id %curWinId%
return
}
El.Click()
;AutomationId=video-effects-and-avatar-button, Name: Hide or Show
El := TeamsEl.WaitElementExistByNameAndType(File,"Checkbox",,2,,1000) ; TODO Lang ; matchmode contains
;Type: Checkbox, Name <FileName> background effect
If !El {
;error notification
PowerTools_ErrDlg("UIA Element not found!")
WinActivate, ahk_id %curWinId%
return
}
El.Click()
; Button Name=Apply
El := TeamsEl.FindFirstByNameAndType("Apply","Button",,3) ; TODO Lang ; matchmode exact
If El
El.Click()
; Close video effects
El := TeamsEl.FindFirstBy("AutomationId=rail-header-close-button")
El.Click()
WinActivate, ahk_id %curWinId%
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_MeetingBackgroundSettings() {
; Open Background Settings
WinId := Teams_GetMeetingWindow()
If !WinId ; empty
return
WinActivate, ahk_id %WinId%
UIA := UIA_Interface()
TeamsEl := UIA.ElementFromHandle(WinId)
; Check if rail pane already opened - if yes close it
El := TeamsEl.FindFirstBy("AutomationId=rail-header-close-button")
El.Click()
TeamsEl.WaitElementNotExist("AutomationId=rail-header-close-button")
El.Click()
; Click on More -> Video Effects
El := TeamsEl.FindFirstBy("AutomationId=callingButtons-showMoreBtn")
El.Click()
El := TeamsEl.WaitElementExist("AutomationId=video-effects-and-avatar-button",,,,1000)
El.Click()
Name := Teams_GetLangName("ShowAllBackgrounds","Show all background effects")
El := TeamsEl.WaitElementExistByName(Name,,1,false,1000) ; 1 match mode start with
If !El {
;error notification
PowerTools_ErrDlg("UIA Element 'Show all backgrounds' not found!")
WinActivate, ahk_id %curWinId%
return
}
El.Click()
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_BackgroundFile2Name(File:="",mode:="r"){
; Name := Teams_BackgroundFile2Name(File:="",mode:="r")
; If no File input, user will be prompted to select an image file
; If mode is "w" (write) user can change the name value if already existing
If GetKeyState("Ctrl") {
Teamsy_Help("bgs")
return
}
If (File = "") { ; Select File
BackgroundDir := Teams_BackgroundGetFolder(false)
FileSelectFile, File, 1, %BackgroundDir%,Select a background image
If ErrorLevel
return
Px := PathX(File)
File := Px.File
File := StrReplace(File, "_thumb.",".") ; in case thumbnail was selected
}
If !FileExist("PowerTools.ini") {
;PowerTools_ErrDlg("No PowerTools.ini file found!")
return
}
IniRead, TeamsBackgroundNames, PowerTools.ini,Teams,TeamsBackgroundNames
;If (TeamsBackgroundNames="ERROR") {
; PowerTools_ErrDlg("TeamsBackgroundNames key not found in PowerTools.ini file [Teams] section!")
; return
;}
If (TeamsBackgroundNames="ERROR") or (TeamsBackgroundNames="[]") or (TeamsBackgroundNames="")
Goto InputName
JsonObj := Jxon_Load(TeamsBackgroundNames)
For i, bg in JsonObj
{
file_i := bg["file"]
If (File = file_i) {
Name := bg["name"]
break
}
}
If !(Name = "") and (mode = "r")
return Name
; Input name
InputName:
;InputBox, OutputVar , Title, Prompt, Hide, Width, Height, X, Y, Locale, Timeout, Default
InputBox, NewName , Background Name, Enter name:,,200,125,,,,,%Name%
If ErrorLevel
return
If (NewName = Name) ; no changes
return Name
Name := NewName
If (TeamsBackgroundNames="ERROR") or (TeamsBackgroundNames="[]") or (TeamsBackgroundNames="")
NewTeamsBackgroundNames = [{"file":"%File%","name":"%Name%"}]
Else {
sPat = "file":"%File%","name":"([^"]*)"
If RegExMatch(TeamsBackgroundNames,sPat,sMatch) { ; replace
sNeedle = "file":"%File%","name":"%sMatch1%"
sRep = "file":"%File%","name":"%Name%"
NewTeamsBackgroundNames := StrReplace(TeamsBackgroundNames,sNeedle,sRep)
} Else { ; append
NewTeamsBackgroundNames := SubStr(TeamsBackgroundNames,1,-1)
NewTeamsBackgroundNames = %NewTeamsBackgroundNames%,{"file":"%File%","name":"%Name%"}]
}
}
; Save to Ini file
IniWrite, %NewTeamsBackgroundNames%, PowerTools.ini,Teams,TeamsBackgroundNames
return Name
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
CreateGUID()
;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=4732
{
VarSetCapacity(pguid, 16, 0)
if !(DllCall("ole32.dll\CoCreateGuid", "ptr", &pguid)) {
size := VarSetCapacity(sguid, (38 << !!A_IsUnicode) + 1, 0)
if (DllCall("ole32.dll\StringFromGUID2", "ptr", &pguid, "ptr", &sguid, "int", size))
return StrGet(&sguid)
}
return ""
}
; -------------------------------------------------------------------------------------------------------------------
Teams_Emails2ChatDeepLink(sEmailList, askOpen:= true){
; Copy Chat Link to Clipboard and ask to open
sLink := "https://teams.microsoft.com/l/chat/0/0?users=" . StrReplace(sEmailList, ";",",")
If InStr(sEmailList,";") { ; Group Chat
InputBox, sTopicName, Enter Group Chat Name,,,,100
if (ErrorLevel=1) { ; no TopicName defined
sLinkDisplayText = Group Chat Link
} Else { ; No topic defined
sLink := sLink . "&topicName=" . StrReplace(sTopicName, ":", "")
sLinkDisplayText = %sTopicName% (Group Chat Link)
}
} Else {
sName := RegExReplace(sEmailList,"@.*" ,"")
sName := StrReplace(sName,"." ," ")
StringUpper, sName, sName , T
sLinkDisplayText = Chat with %sName%
;InputBox, sTopicName, Chat Link Display Name,,,,100,,,,, %sLinkDisplayText%
}
sHtml = <a href="%sLink%">%sLinkDisplayText%</a>
Clip_SetHtml(sHtml,sLink)
If askOpen {
MsgBox 0x1034,People Connector, Teams link was copied to the clipboard. Do you want to open the Chat?
IfMsgBox Yes
Run, %sLink%
}
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_Emails2Chat(sEmailList,sTopicName :=""){
; Open Teams 1-1 Chat or Group Chat from list of Emails
; See https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/build-and-test/deep-link-teams
sLink := "https://teams.microsoft.com/l/chat/0/0?users=" . StrReplace(sEmailList, ";",",")
If InStr(sEmailList,";") { ; Group Chat
InputBox, sTopicName , To Chat, Enter Group Chat Name, , , , , , , ,%sTopicName%
if (ErrorLevel=0) { ; TopicName defined
sLink := sLink . "&topicName=" . StrReplace(sTopicName, ":", "")
}
}
Run, %sLink%
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
; -------------------------------------------------------------------------------------------------------------------
Teams_OpenChat(sSelection := "") {
; Use Selection or Outlook Object
If WinActive("ahk_exe Outlook.exe") {
olApp := ComObjActive("Outlook.Application")
oItem := Outlook_GetCurrentItem(olApp)
Switch Outlook_Item2Type(oItem) {
Case "Mail":
sTopicName := "[Email] " . oItem.Subject
Case "Meeting": ; From Inbox Meeting Request
oItem := oItem.GetAssociatedAppointment(False)
sTopicName := "[Meeting] " . oItem.Subject
Case "Appointment":
sTopicName := "[Meeting] " . oItem.Subject
}
sEmailList := Outlook_Item2Emails(oItem,,True)
If (sEmailList=="") {
return
}
; TODO Remove own email address
Teams_Emails2Chat(sEmailList,sTopicName)
} Else {
Teams_Selection2Chat(sSelection)
}
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_Selection2Chat(sSelection:=""){
; Selection to Chat
; Called from Launcher 2c command
If (sSelection == "")
sSelection := People_GetSelection()
sEmailList := People_GetEmailList(sSelection)
If (sEmailList = "") {
TrayTipAutoHide("Teams:Emails2Chat warning!","No email could be found in current selection!")
return
}
Teams_Emails2Chat(sEmailList)
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_Emails2Meeting(sEmailList){
; Create and Open Teams Meeting from list of Emails
sLink := "https://teams.microsoft.com/l/meeting/new?attendees=" . StrReplace(sEmailList, ";",",")
Teams_OpenUrl(sLink)
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_Link2Fav(sUrl:="",FavsDir:="",sFileName :="") {
; Called by Email2TeamsFavs
; Create Shortcut file
If GetKeyState("Ctrl") {
Run, "https://tdalon.blogspot.com/2021/03/teams-shortcuts-favorites.html"
return
}
If (sUrl="") {
sUrl := Clipboard
}
If (sUrl="") or !(sUrl ~= "https://teams.microsoft.com/*") {
; TODO Def Team name
If RegExMatch(sLink,"https://teams.microsoft.com/l/channel/[^/]*/([^/]*)\?.*",sChannelName)
linktext = %sChannelName1% (Channel)
Else
linktext = Team Name (Team)
InputBox, sUrl , Teams Fav Target, Paste Teams Link:, , 640, 125,,,,, %linktext%
If ErrorLevel
return
}
; folder does not end with filesep
If !(FavsDir) {
sKeyName := "TeamsFavsDir"
RegRead, StartingFolder, HKEY_CURRENT_USER\Software\PowerTools, %sKeyName%
FileSelectFolder, FavsDir , *%StartingFolder%, ,Select folder to store your Teams Shortcut:
If ErrorLevel
return
}
If !(sFileName) {
sFileName := Teams_Link2Text(sUrl)
InputBox, sFileName , Teams Fav File name, Enter the File name:, , 300, 125,,,,, %sFileName%
If ErrorLevel
return
}
sFile := FavsDir . "\" . sFileName . ".url"
;FileDelete %sFile%
IniWrite, %sUrl%, %sFile%, InternetShortcut, URL
; Add icon file:
If Teams_IsNew()
TeamsExe := Teams_GetExe()
Else
TeamsExe = C:\Users\%A_UserName%\AppData\Local\Microsoft\Teams\Update.exe
IniWrite, %TeamsExe%, %sFile%, InternetShortcut, IconFile
IniWrite, 0, %sFile%, InternetShortcut, IconIndex
; Save FavsDir to Settings in registry
SplitPath, sFile, sFileName, FavsDir
PowerTools_RegWrite("TeamsFavsDir",FavsDir)
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_FavsSetDir(){
RegRead, StartingFolder, HKEY_CURRENT_USER\Software\PowerTools, TeamsFavsDir
FileSelectFolder, sKeyValue , StartingFolder, Options, Select folder for your Teams Favorites:
If ErrorLevel
return
PowerTools_RegWrite("TeamsFavsDir",sKeyValue)
return sKeyValue
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_FavsOpenDir(){
RegRead, FavDir, HKEY_CURRENT_USER\Software\PowerTools, TeamsFavsDir
If (FavDir ="") {
Teams_FavsSetDir()
return
}
Run, "%FavDir%"
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_FavsOpen(sInput) {
If (sInput="") {
Teams_FavsOpenDir()
Return
}
; List .lnk files in FavDir
RegRead, FavDir, HKEY_CURRENT_USER\Software\PowerTools, TeamsFavsDir
If (FavDir ="") {
TrayTipAutoHide("Teamsy: OpenFav!","No Favorites directory!")
return
}
sInput := Trim(sInput)
sPat := StrReplace(sInput," ","[^\s]*\s")
Loop, Files, %FavDir%\*.url, R ; recurse in subdirectories
{
If RegExMatch(SubStr(A_LoopFileName, 1,-4),"i)" . sPat) { ; LoopFileName contains extension; ignore case
;Run, %A_LoopFileFullPath%
OpenFavUrl(A_LoopFileFullPath)
return
}
} ; end loop
Loop, Files, %FavDir%\*.lnk, R ; recurse in subdirectories
{
If RegExMatch(SubStr(A_LoopFileName, 1,-4),"i)" . sPat) { ; LoopFileName contains extension; ignore case
Run, %A_LoopFileFullPath%
return
}
} ; end loop
sMsg := "No Favorite found matching '", . sPat . "'."
TrayTipAutoHide("Teamsy: OpenFav!",sMsg)
} ; eofun
OpenFavUrl(File) {
; Opens Internet Shortcuts .url files and close left-over browser window
; Assumes Edge Browser is installed. Window History won't be changed
; Extract url from Shortcut
IniRead, sUrl, %File%, InternetShortcut, URL
Teams_OpenUrl(sUrl)
} ; eofun
Teams_OpenUrl(sUrl) {
; Open Teams Url without Leftover
TeamsExe := Teams_GetExeName()
EdgeWinId := WinActive("ahk_exe msedge.exe")
Run, msedge.exe "%sUrl%" " --new-window"
If EdgeWinId
WinWaitNotActive, ahk_id %EdgeWinId%
Else
WinWaitActive, ahk_exe msedge.exe
NewEdgeWinId := WinExist("ahk_exe msedge.exe")
WinWaitActive, ahk_exe %TeamsExe%,,2
If !ErrorLevel {
If WinExist("ahk_id " . NewEdgeWinId) {
WinActivate
Send ^w ; Close leftover browser window
}
}
} ; eofun
; -------------------------------------------------------------------------------------------------------------------
Teams_FavsAdd(){
; Add to Favorites: either link or Email List
; Called from Launcher f+ command
sInput := Clip_GetSelection()
If (sInput="") {
sInput := Clipboard
}
If RegExMatch(sInput,"^http.*"){ ; Link
Teams_Link2Fav(sInput)
} Else {
Teams_Emails2Favs(sInput)
}
} ; eofun
; ----------------------------------------------------------------------
Teams_Emails2Favs(sInput:= ""){
; Calls: Email2TeamsFavs
If GetKeyState("Ctrl") {
Run, "https://tdalon.blogspot.com/2021/03/teams-people-favorites.html"
return
}
If (sInput ="") {
sInput := People_GetSelection()
If (sInput = "") {
TrayTipAutoHide("Teams: Emails to Favs!","Nothing selected or Clipboard empty!")
return
}
}
sEmailList := People_GetEmailList(sInput)
If (sEmailList = "") {
TrayTipAutoHide("Teams: Emails to Favs!","No email could be found from Selection or Clipboard!")
return
}
RegRead, FavsDir, HKEY_CURRENT_USER\Software\PowerTools, TeamsFavsDir
If ErrorLevel {
FavDirs := Teams_FavsSetDir()
If FavDirs = ""
return
}
FileSelectFolder, FavsDir , *%FavsDir%, ,Select folder to store your Teams Contact Shortcuts:
If ErrorLevel
return
Loop, parse, sEmailList, ";"
{
Email2TeamsFavs(A_LoopField,FavsDir)
}
Run %FavsDir% ; open Favorites directory
} ; eofun
; ----------------------------------------------------------------------
Email2TeamsFavs(sEmail,FavsDir){
; Calls: Teams_Link2Fav, Teams_FavsAdd
; Get Firstname
sName := RegExReplace(sEmail,"\..*" ,"")
StringUpper, sName, sName , T
; 1. Create Chat Shortcut
sUrl = https://teams.microsoft.com/l/chat/0/0?users=%sEmail%
Teams_Link2Fav(sUrl,FavsDir,"Chat " + sName)
; 2. Create Call shortcut
sFile := FavsDir . "\Call " . sName . ".vbs"
; write code
TeamsExe := Teams_GetExe()
sText = CreateObject("Wscript.Shell").Run "%TeamsExe% callto:%sEmail%"
; Create empty File
FileDelete %sFile%
FileAppend , %sText%, %sFile%
; create shortcut
sLnk := PathX(sFile, "Ext:.lnk").Full
FileCreateShortcut, %sFile%, %sLnk%,,,, %TeamsExe%
} ; eofun
; NOT USED ########################
Emails2TeamsFavGroupChat(sEmailList){
RegRead, FavsDir, HKEY_CURRENT_USER\Software\PowerTools, TeamsFavsDir
If ErrorLevel {
FavDirs := Teams_FavsSetDir()
If FavDirs = ""
return
}
FileSelectFolder, FavsDir , *%StartingFolder%, ,Select folder to store your Teams Shortcut:
If ErrorLevel
return
sUrl := "https://teams.microsoft.com/l/chat/0/0?users=" . StrReplace(sEmailList, ";",",")
InputBox, sName, Enter Chat Group name,,,,100
if ErrorLevel
return
sName := StrReplace(sName, ":", "")
sLink := sLink . "&topicName=" . sName
Teams_Link2Fav(sUrl,FavsDir,"Group Chat -" . sName)
} ; eofun
; ----------------------------------------------------------------------
Teams_IsNew(){ ; @fun_teams_isnew@
; IsNew := Teams_IsNew()
; return true or false depending if Teams New Client is installed and Classic Teams running
static IsNew
If !(IsNew = "") {
;MsgBox IsNew:%IsNew%
return IsNew
}
fExe = C:\Users\%A_UserName%\AppData\Local\Microsoft\WindowsApps\ms-teams.exe
If !(FileExist(fExe)) { ; New Teams not installed
IsNew := False
return IsNew
}
Process, Exist, ms-teams.exe
If Not (ErrorLevel= 0) {
;Classic Teams
IsNew:=True
return IsNew
}
; Check if a Teams process is running ; need to disable Microsoft Teams classic in Startup to work at startup
Process, Exist, Teams.exe
If Not (ErrorLevel= 0) {
;Classic Teams
IsNew := False
return IsNew
}
; Possibility to overwrite in ini file if Teams is not started
If FileExist("PowerTools.ini") {
IniRead, IniIsNew, PowerTools.ini,Teams,TeamsIsNew
If !(IniIsNew="ERROR") {
IsNew := IniIsNew
return IsNew
}
}
IsNew:=True
return IsNew
} ;eofun
; ----------------------------------------------------------------------
Teams_GetExe() {
If Teams_IsNew()
; New Teams in WindowsApp C:\Users\%A_UserName%\AppData\Local\Microsoft\WindowsApps
fExe = C:\Users\%A_UserName%\AppData\Local\Microsoft\WindowsApps\ms-teams.exe
Else { ; Classic Team Client
;EnvGet, userprofile , userprofile
;fExe = %userprofile%\AppData\Local\Microsoft\Teams\current\Teams.exe ;C:\Users\%A_UserName%\AppData\Local\Microsoft\Teams\Update.exe
fExe = C:\Users\%A_UserName%\AppData\Local\Microsoft\Teams\current\Teams.exe
}
return fExe
}
Teams_RunExe(){
If Teams_IsNew() {
; New Teams in WindowsApp C:\Users\%A_UserName%\AppData\Local\Microsoft\WindowsApps
fExe := "ms-teams.exe"
Run, %fExe%
} Else { ; Classic Team Client
;fExe = C:\Users\%A_UserName%\AppData\Local\Microsoft\Teams\current\Teams.exe
;fExe = C:\Users\%A_UserName%\AppData\Local\Microsoft\Teams\Update.exe --processStart "Teams.exe"
Run, "C:\Users\%A_UserName%\AppData\Local\Microsoft\Teams\Update.exe" --processStart "Teams.exe"
}
} ;eofun
; ----------------------------------------------------------------------
; ----------------------------------------------------------------------
Teams_GetExeName(IsNew:=""){
If Teams_IsNew()
return "ms-teams.exe"
Else
return "Teams.exe"
} ;eofun
; ----------------------------------------------------------------------
Teams_SharingControlBar(mode:="-") {
; Teams_SharingControlBar(mode:="-")
; mode is '+' pr '-'. Empty will toggle
If GetKeyState("Ctrl") {
Teamsy_Help("sb")
return
}
Lang := Teams_GetLang()
Prop := "SharingControlBar"
Name := Teams_GetLangName(Prop,"Sharing control bar",Lang)
If (Name="")
return
TeamsExe := Teams_GetExeName()
wTitle = %Name% ahk_exe %TeamsExe%
Switch mode {
Case "-":
WinHide, %wTitle%
return
Case "+":
WinShow, %wTitle%
return
Default:
If WinExist(wTitle)
WinHide, %wTitle%
Else
WinShow, %wTitle%
}
} ; eofun
; ----------------------------------------------------------------------
; ----------------------------------------------------------------------
Teams_Selection2Team() {
; Calls: Teams_Emails2Team
sSelection := People_GetSelection()
sEmailList := People_GetEmailList(sSelection)
If (sEmailList = "") {
TrayTipAutoHide("TeamsShortcuts warning!","No email could be found in selection or clipboard!")
return
}
Teams_Emails2Team(sEmailList)
} ; eofun
; ----------------------------------------------------------------------
Teams_Emails2Team(EmailList,TeamLink:=""){
; Syntax:
; Teams_Emails2Team(EmailList,TeamLink*)
; EmailList: String of email adresses separated with a ;
; TeamLink: (String) optional. If not passed, user will be asked via inputbox
; e.g. https://teams.microsoft.com/l/team/19%3a12d90de31c6e44759ba622f50e3782fe%40thread.skype/conversations?groupId=640b2f00-7b35-41b2-9e32-5ce9f5fcbd01&tenantId=xxx
; Requires PowerShell
; Calls: Teams_PowerShellCheck
If !Teams_PowerShellCheck()
return
If (TeamLink=="") {
InputBox, TeamLink , Team Link, Enter Team Link:,,640,125
if ErrorLevel
return
}
;
sPat = \?groupId=(.*)&tenantId=(.*)
If !(RegExMatch(TeamLink,sPat,sId)) {
MsgBox 0x10, Error, Provided Url does not match a Team Link!
return
}
sGroupId := sId1
sTenantId := sId2
; Create csv file with list of emails
CsvFile = %A_Temp%\email_list.csv
If FileExist(CsvFile)
FileDelete, %CsvFile%
sText := StrReplace(EmailList,";","`n")
FileAppend, %sText%,%CsvFile%
; Create .ps1 file
PsFile = %A_Temp%\Teams_AddUsers.ps1
; Fill the file with commands
If FileExist(PsFile)
FileDelete, %PsFile%
Domain := People_GetDomain()
If (Domain ="") {
MsgBox 0x10, Teams Shortcuts: Error, No Domain defined!
return
}
OfficeUid := People_GetMyOUid()
sText = Connect-MicrosoftTeams -TenantId %sTenantId% -AccountId %OfficeUid%@%Domain%
sText = %sText%`nImport-Csv -header email -Path "%CsvFile%" | foreach{Add-TeamUser -GroupId "%sGroupId%" -user $_.email}
FileAppend, %sText%,%PsFile%
; Run it
RunWait, PowerShell.exe -NoExit -ExecutionPolicy Bypass -Command %PsFile% ;,, Hide
;RunWait, PowerShell.exe -ExecutionPolicy Bypass -Command %PsFile% ,, Hide
}
; ----------------------------------------------------------------------
Teams_ExportTeams() {
; CsvFile := Teams_ExportTeams
; returns empty if not created/ failed
; Requires PowerShell
If GetKeyState("Ctrl") {
Teamsy_Help("t2xl")
return
}
If Not Teams_PowerShellCheck()
return
CsvFile = %A_ScriptDir%\Teams_list.csv
If FileExist(CsvFile)
FileDelete, %CsvFile%
; Create .ps1 file
PsFile = %A_Temp%\Teams_ExportTeams.ps1
; Fill the file with commands
If FileExist(PsFile)
FileDelete, %PsFile%
Domain := People_GetDomain()
If (Domain ="") {
MsgBox 0x10, Teams Shortcuts: Error, No Domain defined!
return
}
OfficeUid := People_GetMyOUid()
sText = Connect-MicrosoftTeams -AccountId %OfficeUid%@%Domain%
sText = %sText%`nGet-Team -User %OfficeUid%@%Domain% | Select DisplayName, MailNickName, GroupId, Description | Export-Csv -Path %CsvFile% -NoTypeInformation
FileAppend, %sText%,%PsFile%
; Run it;RunWait, PowerShell.exe -NoExit -ExecutionPolicy Bypass -Command %PsFile% ;,, Hide
RunWait, PowerShell.exe -ExecutionPolicy Bypass -Command %PsFile% ,, Hide
return CsvFile
}
; ----------------------------------------------------------------------
Teams_PowerShellCheck() {
; returns True if Teams PowerShell is setup, False else
RegRead, TeamsPowerShell, HKEY_CURRENT_USER\Software\PowerTools, TeamsPowerShell
If (TeamsPowerShell := !TeamsPowerShell) {
sUrl := "https://tdalon.blogspot.com/2020/08/teams-powershell-setup.html"
Run, "%sUrl%"
MsgBox 0x1024,People Connector, Have you setup Teams PowerShell on your PC?
IfMsgBox No
return False
OfficeUid := People_GetMyOUid()
PowerTools_RegWrite("TeamsPowerShell",TeamsPowerShell)
return True
} Else ; was already set
return True