forked from TLMcode/AHKs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FcnLib (cr-48-ubuntu's conflicted copy 2012-11-15).ahk
2496 lines (2144 loc) · 79.1 KB
/
FcnLib (cr-48-ubuntu's conflicted copy 2012-11-15).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
#SingleInstance Force
#include thirdParty/Functions.ahk
#include thirdParty/CmdRet.ahk
#include thirdParty/Cycle.ahk
#include thirdParty/Format4Csv.ahk ;haven't used this yet, but I should
#include FcnLib-Rewrites.ahk
#include FcnLib-IniStats.ahk
#include FcnLib-GetUrlBar.ahk
#include FcnLib-Nightly.ahk ;this was mainly added for FastNotification()
;#include thirdParty\Notify.ahk ;this causes windows to be open forever
;Takes a screenshot and saves it to the specified path
;Useful for debugging macros afterward
;Includes an optional text parameter that will allow you to
;begin the filename with a relevant text description, and
;end it with a timestamp
;not implemented: adjust image quality, change image format
;PARAMETERS:
; descriptiveText - prepended onto the front of the filename
; directoryPath - a path, "dropbox" or "local"
; options - "activeWindow"
;FIXME screenshot capability is broken
#include thirdParty/ScreenCapture.ahk
SaveScreenshot(descriptiveText="", directoryPath="dropbox", options="")
{
;TODO LowRes option
;TODO HighRes option
captureArea=0
if InStr(options, "activeWindow")
captureArea=1
if (directoryPath="") ;default
directoryPath=dropbox
if (directoryPath="dropbox")
directoryPath=C:\Dropbox\AHKs\gitExempt\screenshots\%A_ComputerName%
else if (directoryPath="local")
directoryPath=C:\DataExchange\PrintScreen
FileCreateDir, %directoryPath%
FormatTime FileNameText,, yyyyMMddHHmmss
fullfilename = %directoryPath%\%descriptiveText%%FileNameText%.bmp
CaptureScreen(captureArea,true,fullfilename)
;addToTrace(fullFilename)
}
SaveScreenshot2()
{
timestamp := CurrentTime("hyphenated")
filenameJpg=C:\Dropbox\AHKs\gitExempt\screenshots\%A_ComputerName%\%timestamp%.jpg
jpegQuality := 60
;take a screenshot of the specified area
pToken:=Gdip_Startup()
pBitmap:=Gdip_BitmapFromScreen("0|0|" A_ScreenWidth "|" A_ScreenHeight)
Gdip_SaveBitmapToFile(pBitmap, filenameJpg, jpegQuality)
Gdip_Shutdown(pToken)
}
;Sleeps for a specified number of minutes
SleepMinutes(minutes)
{
SleepSeconds(minutes*60)
}
;Sleeps for a specified number of seconds
SleepSeconds(seconds)
{
Sleep 1000*seconds
}
;Determines whether or not we should show debug msgs
;TODO add a logging mode?
;not yet finished, just throwing around some ideas
;OptionalDebug(options="", millionParams="...really, lots of params, like 15..")
OptionalDebug(textOrOptions="Hello World!", text1="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text2="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text3="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text4="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text5="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text6="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text7="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text8="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text9="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text10="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text11="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text12="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text13="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text14="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text15="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ")
{
global A_Debug
global A_Log
if ( InStr(options, "Debug") || A_Debug )
debug(textOrOptions, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15)
if ( InStr(options, "Log") || A_Log )
delog(textOrOptions, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15)
}
CustomTitleMatchMode(options="")
{
;By default this uses RegEx and Fast (no hidden window text detected)
if (InStr(options, "Start"))
SetTitleMatchMode, 1
else if (InStr(options, "Contain") || InStr(options, "Anywhere"))
SetTitleMatchMode, 2
else if (InStr(options, "Exact"))
SetTitleMatchMode, 3
else if (InStr(options, "RegEx"))
SetTitleMatchMode, RegEx
else if (InStr(options, "Default"))
{
SetTitleMatchMode, 2
;SetTitleMatchMode, Fast
}
else
SetTitleMatchMode, RegEx
;FIXME haxor... wrong method (will cause side effects)
;SendMode, Event
}
ForceWinFocus(titleofwin, options="")
{
returned:=false
prevMode :=A_TitleMatchMode
prevSpeed:=A_TitleMatchModeSpeed
CustomTitleMatchMode(options)
OptionalDebug(options, titleofwin)
;TODO don't do it if a matching window is already active
IfWinActive, %titleofwin%,
returned:=true
else
{
Loop
{
WinWait, %titleofwin%, , 1
IfWinNotActive, %titleofwin%,
WinActivate, %titleofwin%,
WinWaitActive, %titleofwin%, , 1
IfWinActive, %titleofwin%,
{
returned:=true
break
}
}
}
SetTitleMatchMode, %prevMode%
SetTitleMatchMode, %prevSpeed%
return returned
}
;NOTE this is not the same because it checks if the window already exists first
; rather than just waiting forever for the window
;TODO probably should merge these two methods (with an ifexist option)
;or we could have a timeout option that waits for the specified
;number of seconds and then just returns false
ForceWinFocusIfExist(titleofwin, options="")
{
returned:=false
prevMode :=A_TitleMatchMode
prevSpeed:=A_TitleMatchModeSpeed
CustomTitleMatchMode(options)
OptionalDebug(options, titleofwin)
IfWinExist, %titleofwin%,
{
WinWait, %titleofwin%,
IfWinNotActive, %titleofwin%,
WinActivate, %titleofwin%,
WinWaitActive, %titleofwin%,
returned:=true
}
;CustomTitleMatchMode("Default")
SetTitleMatchMode, %prevMode%
SetTitleMatchMode, %prevSpeed%
return returned
}
;TODO not sure if the return values here are good or if they suck!
;Closes the window if it exists, then returns true if it actually did exist in the first place
WinClose(titleofwin, options="")
{
prevMode :=A_TitleMatchMode
prevSpeed:=A_TitleMatchModeSpeed
CustomTitleMatchMode(options)
OptionalDebug(options, titleofwin)
IfWinExist, %titleofwin%,
{
WinClose, %titleofwin%,
returned:=true
}
;CustomTitleMatchMode("Default")
SetTitleMatchMode, %prevMode%
SetTitleMatchMode, %prevSpeed%
return returned
}
;TODO deprecate/rename this critter
CloseWin(titleofwin, options="")
{
WinClose(titleofwin, options)
}
;TESTME
SendViaClipboard(text)
{
Sleep 100
;Save previous clipboard item
ClipSaved := ClipboardAll
Sleep 100
;Put item on the clipboard
Clipboard := text
;May need to wait for a while
ClipWait, 1
MaxTimeToWait:=CurrentTimePlus(1)
while (!CurrentlyAfter(MaxTimeToWait))
{
if (text==Clipboard)
break
if (text==ClipboardAll)
break
Sleep 50
}
Sleep 100
;Paste
Send, ^v
Sleep 100
;Restore clipboard contents, clear memory for storage variable
Clipboard := ClipSaved
ClipSaved=
Sleep 100
}
SimpleImageSearchWithDimensions(filename, xStart, yStart, width, height)
{
;TODO merge this mode into the others
;should probably have a usage that looks like:
; SimpleImageSearch("file.bmp", "{CoordZone:\"0,0,10,20\"}")
;should use json to specify the coordzone to search
if NOT FileExist(filename)
{
errord(A_ThisFunc, filename, "the aforementioned file does not exist")
return false
}
;WinGetPos, no, no, winWidth, winHeight, A
ImageSearch, xvar, yvar, xStart, yStart, width, height, %filename%
return NOT ErrorLevel
}
SimpleImageSearch(filename)
{
if NOT FileExist(filename)
{
errord(A_ThisFunc, filename, "the aforementioned file does not exist")
return false
}
WinGetPos, no, no, winWidth, winHeight, A
ImageSearch, xvar, yvar, 0, 0, winWidth, winHeight, %filename%
returned := ! ERRORLEVEL
;FOR DEBUGGING ONLY
;if returned
;AddToTrace("Saw image: " . filename)
return returned
}
;If you see the image, move the mouse there
MouseMoveIfImageSearch(filename)
{
if NOT FileExist(filename)
{
errord(A_ThisFunc, filename, "the aforementioned file does not exist")
return false
}
WinGetPos, no, no, winWidth, winHeight, A
ImageSearch, xvar, yvar, 0, 0, winWidth, winHeight, %filename%
MouseMove, xvar, yvar
return NOT ErrorLevel
}
;If you see the image, click it
ClickIfImageSearch(filename, options="left mouse")
{
;TODO make this look a little more like:
;if NOT VerifyFileExist(A_ThisFunc, filename)
;return false
;if ErrordIfFileNotExist(A_ThisFunc, filename)
;return false
;if NOT FileExist(filename)
;{
;errord(A_ThisFunc, filename, "the aforementioned file does not exist")
;return false
;}
WinGetPos, no, no, winWidth, winHeight, A
ImageSearch, xvar, yvar, 0, 0, winWidth, winHeight, %filename%
if NOT ErrorLevel
Click(xvar, yvar, options)
return NOT ErrorLevel
}
;Wait until a certain image appears
WaitForImageSearch(filename, variation=0, timeToWait=60, sleepTime=20) ;TODO option to exit ahk if image was not found
{
if NOT FileExist(filename)
{
errord(A_ThisFunc, filename, "the aforementioned file does not exist")
return false
}
TimeToStop:=CurrentTimePlus(timeToWait)
while (CurrentlyBefore(TimeToStop))
{
WinGetPos, no, no, winWidth, winHeight, A
ImageSearch, no, no, 0, 0, winWidth, winHeight, *%variation% %filename%
if NOT ErrorLevel
return true
Sleep, sleepTime
}
delog(A_ThisFunc, "the function was waiting for the image to appear, but timed out", filename, variation, timeToWait, sleepTime)
return false
}
WFCIImageSearch(filename, options="left mouse")
{
WaitForImageSearch(filename)
ClickIfImageSearch(filename, options)
}
;FIXME I don't like the boolean logic here... just doesn't seem readable
ErrordIfFileNotExist(ThisFunc, filename)
{
if NOT FileExist(filename)
{
errord(ThisFunc, filename, "the aforementioned file does not exist")
return false
}
return true
}
IsRegExMatch(Haystack, Needle)
{
return RegExMatch(Haystack, Needle)<>""
}
Remap(input, remap1, replace1, remap2=0, replace2=0, remap3=0, replace3=0, remap4=0, replace4=0, remap5=0, replace5=0, remap6=0, replace6=0)
{
if input=remap1
return %replace1%
if input=remap2
return %replace2%
if input=remap3
return %replace3%
if input=remap4
return %replace4%
if input=remap5
return %replace5%
if input=remap6
return %replace6%
return input
}
;I now think that moving to 0,0 is a better solution (most of the time)
MouseMoveRandom()
{
WinGetPos, no, no, winWidth, winHeight
Random, xCoordinate, 0, winWidth
Random, yCoordinate, 0, winHeight
MouseMove, xCoordinate, yCoordinate
}
;deprecated:
MoveToRandomSpotInWindow()
{
MouseMoveRandom()
}
WeightedRandom(OddsOfa1, OddsOfa2, OddsOfa3=0, OddsOfa4=0, OddsOfa5=0)
{
Random, input, 1, 100
;debug(input)
OddsOfa2+=OddsOfa1
OddsOfa3+=OddsOfa2
OddsOfa4+=OddsOfa3
OddsOfa5+=OddsOfa4
if % input<=OddsOfa1
return 1
if % input<=OddsOfa2
return 2
if % input<=OddsOfa3
return 3
if % input<=OddsOfa4
return 4
if % input<=OddsOfa5
return 5
return 6
}
;TODO need to expand this so that it is called for each argument (warnings for true, false, 0, 1, or null string)
;Shows a debug message for a bool ("true" or "false")
DebugBool(bool)
{
;possible msgs:
;WARNING: This variable may be equal to false, 0, or may be undefined or empty
;WARNING: This variable may be equal to true or 1
if (bool==1)
msg:="This variable may be true or 1"
else if (bool==0)
msg:="This variable may be false or 0"
else if (bool=="")
msg:="This variable may be undef or an empty string"
else
msg:=bool
;Debug(msg) ;this must go before we put it into debug (endless recursion?)
return msg
}
;TODO maybe get rid of this in favor of debugbool
;Change a boolean to a string (more readable)
BoolToString(bool)
{
if (bool)
return "true"
else
return "false"
}
;WRITEME
;Returns true if color1 is darker than color2
ColorIsDarkerThan(color1, color2)
{
;split into rgb numbers
;add rgb
;determine difference
}
;WRITEME
;Continuously checks a pixel's color until it stabilizes at a certain color
;returns the color that it is holding at
WaitUntilColorStopsChanging(x, y)
{
PixelGetColor, lastColor, x, y
while lastColor<>currentColor
{
PixelGetColor, currentColor, x, y
Sleep, 50
}
return currentColor
}
;WRITEME
;Keeps clicking a spot until it is as dark/as light as possible
;(for selecting/deselecting a checkbox)
ForcePixelColorChangeByClicking(x, y, lightestOrDarkest, checkboxStates=2)
{
;MouseMove x, y
;current=WaitUntilColorStopsChanging(x, y)
;max=current
;Loop % checkboxStates
;{
;current=WaitUntilColorStopsChanging(x, y)
;if ColorIsDarkerThan(current, max)
; max=current
;}
;while ColorIsDarkerThan(current, max)
;{
;
;current=WaitUntilColorStopsChanging(x, y)
;}
}
;Clicks at a specified location with ControlClick, MouseClick or Click
Click(xCoord, yCoord, options="Left Mouse")
{
numberOfTimesToClick:=1
if (InStr(options, "Double"))
numberOfTimesToClick:=2
Loop %numberOfTimesToClick%
{
if (InStr(options, "Standard"))
{
if (InStr(options, "Right"))
Click, right, %xCoord%, %yCoord%
else
Click, left, %xCoord%, %yCoord%
}
else if (InStr(options, "Mouse"))
{
if (InStr(options, "Right"))
MouseClick, right, %xCoord%, %yCoord%
else
MouseClick, left, %xCoord%, %yCoord%
}
else if (InStr(options, "Control"))
{
if (InStr(options, "Right"))
{
;debug("r c")
ControlClick, x%xCoord% y%yCoord%, , , RIGHT
}
else
ControlClick, x%xCoord% y%yCoord%, , , LEFT
}
else
{
if (InStr(options, "Right"))
Click, right, %xCoord%, %yCoord%
else
Click, left, %xCoord%, %yCoord%
}
}
}
;TODO write
;Closes a window as gracefully as possible
;TODO allow access by process?
CloseWindowGracefully(title, text="", xClickToClose="", yClickToClose="")
{
;Check if winexist each time (then return)
}
CurrentTime(options="")
{
FormatTime, time,, yyyyMMddHHmmss
returned := FormatTime(time, options)
if InStr(options, "extended")
returned .= "-" . A_TickCount
return returned
}
;TODO enable slashes or colons?
;Gets the current time (unique, increasing)
; pass in a FormatTime-style string to customize your format
; or use one of the custom styles already thought up like hyphendate and slashdate
FormatTime(time, options="")
{
;use flags
; date time datetime
; separator
; ordering? YYYYMMDD or MMDDYYYY
if InStr(options, "hyphen")
hyphen:=true
if InStr(options, "slash")
slash:=true
if InStr(options, "colons")
colon:=true
if InStr(options, "date")
date:=true
if InStr(options, "time")
time:=true
if InStr(options, "zeropad")
zeropad:=true
if InStr(options, "year")
month:=true
if InStr(options, "month")
time:=true
if InStr(options, "slashdate")
FormatTime, returned, %time%, MM/dd/yyyy
else if InStr(options, "hyphenated")
FormatTime, returned, %time%, yyyy-MM-dd_HH-mm-ss
else if InStr(options, "hyphendate")
FormatTime, returned, %time%, yyyy-MM-dd
else if InStr(options, "wordsdate")
FormatTime, returned, %time%, MMMM d, yyyy
else if InStr(options, "month")
FormatTime, returned, %time%, MM
else if InStr(options, "year")
FormatTime, returned, %time%, yyyy
else if InStr(options, "date")
FormatTime, returned, %time%, yyyyMMdd
else if options
FormatTime, returned, %time%, %options%
else
FormatTime, returned, %time%, yyyyMMddHHmmss
;got forced into using this
return returned
}
;TESTME
DeFormatTime(timestamp)
{
if RegExMatch(timestamp, "(\d{4}).(\d{2}).(\d{2}).(\d{2}).(\d{2}).(\d{2})", m)
{
returned=%m1%%m2%%m3%%m4%%m5%%m6%
return returned
}
if RegExMatch(timestamp, "(\d{14})", m)
{
returned=%m1%
return returned
}
if RegExMatch(timestamp, "(\d{2}).(\d{2}).(\d{4})", m)
{
returned=%m3%%m1%%m2%000000
return returned
}
if RegExMatch(timestamp, "(\d{4}).(\d{2}).(\d{2})", m)
{
returned=%m1%%m2%%m3%000000
return returned
}
}
;FIXME does not account for 60-99 seconds, etc...
;Gets the current time so that later a time comparison is possible
CurrentTimePlus(seconds)
{
return CurrentTime() + seconds
}
;WRITEME TESTME
TimePlus(one, two)
{
returned:=0
returned+=Mod(one, 100) + Mod(two, 100)
;one/=100
;two/=100
returned+=one
return returned
}
;Checks if the current time is before the time that is passed in
CurrentlyBefore(time)
{
;remove hyphens for flexibility
time:=StringReplace(time, "-")
return CurrentTime() < time
}
;Checks if the current time is after the time that is passed in
CurrentlyAfter(time)
{
;remove hyphens for flexibility
time:=StringReplace(time, "-")
return CurrentTime() > time
;i.e.:
;Debug("starting timer")
;TimeToStop:=CurrentTimePlus(2)
;while true
;{
; sleep 100 ; CheckSomeFooBar()...
;
; if (CurrentlyAfter(TimeToStop))
; break
;}
;Debug(TimeToStop)
}
;Starts a timer--to be used in conjunction with ElapsedTime()
StartTimer()
{
return A_TickCount
}
;TODO rename to StopTimer?
;Provides the elapsed time since StartTimer() was called
ElapsedTime(StartTime)
{
if (StartTime = "")
Errord("You didn't pass a valid StartTime in to the ElapsedTime() function.", "Be sure to use StartTimer() to get the start time.")
returned := A_TickCount - StartTime
return returned
}
;TODO write
;Formats a millisec-time into something a bit more pretty
PrettyTime(TimeToFormat)
{
}
;Determines if the specified window is minimized
IsMinimized(title="", text="")
{
SetTitleMatchMode, RegEx
WinGet, winstate, MinMax, %title%, %text%
IfWinExist, %title%, %text%
{
if (winstate=-1)
return true
}
return false
}
;Determines if the specified window is minimized
IsMaximized(title="", text="")
{
SetTitleMatchMode, RegEx
WinGet, winstate, MinMax, %title%, %text%
IfWinExist, %title%, %text%
{
if (winstate=1)
return true
}
return false
}
;Closes open applications that usually are difficult for windows to shut down (preps for a restart)
CloseDifficultApps()
{
ProcessClose("SupervisionCore.exe")
ProcessClose("SupervisionCore1.exe")
ProcessClose("SupervisionCore2.exe")
ProcessClose("SupervisionCore3.exe")
ProcessClose("winsplit.exe")
;ProcessClose("ssms.exe")
ProcessClose("hpupdate.exe")
ProcessClose("DesktopWeather.exe")
;ProcessCloseAll("ping.exe")
ProcessCloseAll("javaw.exe")
if ForceWinFocusIfExist("Irssi ahk_class PuTTY")
Send, /quit Ragequit{ENTER}
if ForceWinFocusIfExist("ahk_class VMPlayerFrame")
{
Sleep, 500
ForceWinFocus("ahk_class VMPlayerFrame")
Send, {ALT}fx
}
while true
{
IfWinNotExist ahk_class MozillaUIWindowClass
break
WinClose ahk_class MozillaUIWindowClass
}
while true
{
IfWinNotExist, Microsoft SQL Server Management Studio ahk_class wndclass_desked_gsk
break
WinClose, Microsoft SQL Server Management Studio ahk_class wndclass_desked_gsk
WinWait, Microsoft SQL Server Management Studio ahk_class #32770, Save changes to the following items?, 5
WinActivate, Microsoft SQL Server Management Studio ahk_class #32770, Save changes to the following items?
if NOT ErrorLevel
ControlClick, &No
}
while true
{
IfWinNotExist, pgAdmin III ahk_class wxWindowClassNR
break
WinClose, pgAdmin III ahk_class wxWindowClassNR
WinWait, Query ahk_class #32770, Do you want to save changes?, 5
WinActivate, Query ahk_class #32770, Do you want to save changes?
if NOT ErrorLevel
ControlClick, &No
}
while true
{
Process, Exist, chrome.exe
pid:=ERRORLEVEL
if NOT pid
break
PostMessage,0x111,65405,0,,ahk_pid %pid%
Process, WaitClose, %pid%, 1
;if it exists
Process, Exist, %pid%
pid:=ERRORLEVEL
if pid
{
;debug("closing")
Process, Close, %pid%
}
}
}
CloseDifficultAppsAllScreens()
{
DetectHiddenWindows, On
WinShow, SK Sync Server Version 1.0.01A ahk_class SunAwtFrame
WinClose, SK Sync Server Version 1.0.01A ahk_class SunAwtFrame
Loop 5
Send, {BROWSER_BACK}
Loop 5
{
Sleep, 100
CloseDifficultApps()
Send, {BROWSER_FORWARD}
}
;NOTES: forcefield.exe is the stupid thing that comes with ZoneAlarm
listOstuff = ssms.exe,vmware-vmx.exe,vmplayer.exe,FindAndRunRobot.exe,dsidebar.exe,hpupdate.exe,java.exe,ping.exe,ForceField.exe
Loop, parse, listOstuff, CSV
ProcessCloseFifty(A_LoopField)
;ProcessCloseAll(A_LoopField)
}
;WRITEME
;Returns true if the specified path is a directory, false if it is a file (even if it doesn't exist yet)
;WRITEME
;Returns true if the specified path is a file, or false if it is a directory
;TODO Perhaps this should be done with other items, like the windows user folder, or like the dropbox folder
;Returns the correct program files location (error message if the file doesn't exist)
ProgramFilesDir(relativePath)
{
;ensure that the rel path starts with a slash
if NOT SubStr(relativePath, 1, 1)="\"
relativePath=\%relativePath%
;test the standard dir
baseDir:="C:\Program Files"
stdPath=%baseDir%%relativePath%
if (FileExist(stdPath))
return stdPath
;test the x86 dir
x86:=" (x86)"
x86Path=%baseDir%%x86%%relativePath%
if (FileExist(x86Path))
return x86Path
Errord(A_ThisFunc, "was not able to find 'relativePath':", relativePath)
}
QuickFileOutput(text)
{
timestamp := CurrentTime("hyphenated")
file=C:\Dropbox\fastData\quickFileOutput\%timestamp%-%A_ComputerName%.txt
FileCreate(text, file)
}
;Debug vs Errord: Silent/Traytip/Msgbox/Overlay, Logged/Not, Info/Warning/Error
;
;Send an error message with as many parameters as necessary, save debug information to dropbox logs section
debug(textOrOptions="Hello World!", text1="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text2="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text3="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text4="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text5="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text6="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text7="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text8="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text9="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text10="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text11="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text12="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text13="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text14="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text15="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ")
{
loggedMode:=false
silentMode:=false
trayMsgMode:=false
errordMode:=false
printToTraceMode := true
printToIniMode := true
displayTime=2
if (InStr(textOrOptions, "trayMsg"))
trayMsgMode := true
if (InStr(textOrOptions, "silent"))
silentMode := true
if (InStr(textOrOptions, "log"))
loggedMode := true
if (InStr(textOrOptions, "noLog"))
loggedMode := false
if (InStr(textOrOptions, "errord"))
{
errordMode := true
displayTime = 60
}
if (InStr(textOrOptions, "noTimeout"))
displayTime := ""
;TODO screenshot mode for debug() fcn
;if (InStr(textOrOptions, "screenshot"))
;{
;savescreenshot()
;append filename to the end of the debug message
;}
;TODO email/SMS error mode for debug() fcn
;this is probably a bad idea... just leave it in FastNotification()
if NOT IsMyCompy()
{
;TODO make a debug state for getting rid of Dropbox output in Lnx functions
printToTraceMode := false
printToIniMode := false
}
;put together the message
if (errordMode)
messageTitle:="ERROR: "
else
messageTitle:="Debug: "
messageTitle.=CurrentTime("hyphenated")
messageTitle.=A_Space
messageTitle.=A_ScriptFullPath
messageText:="`n " . textOrOptions
loop 15
{
;TODO make that true,false,undef helper function for helpful debug suggestions
;TODO if the one before has a colon at the end, then just add a space instead of a newline
if (text%A_Index% == "ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ")
break
messageText.="`n " . DebugBool( text%A_Index% )
}
messageText.="`n`n"
;log the message right away
if loggedMode
{
logMessage=%messageTitle% %messageText%
;logPath=C:\Dropbox\Public\logs
;logFile=%A_ComputerName%.txt
date := CurrentTime("hyphendate")
if IsMyCompy()
logFileFullPath=C:\Dropbox\Public\logs\%A_ComputerName%.txt
else
logFileFullPath=C:\inetpub\logs\%date%.txt
FileAppend(logMessage, logFileFullPath)
}
;display info to the user
if NOT silentMode
{
if trayMsgMode
{
if (errordMode)
TrayMsg("AHK Error", messageText, 20, 3)
else
TrayMsg("AHK Debug", messageText, 20, 3)
}
else if overlayMode
msgbox, , %messageTitle%, %messageText%, %displayTime%
else
msgbox, , %messageTitle%, %messageText%, %displayTime%
}
;print to ini (iniFpp) I put this in so we could keep some stats for how often this stuff happens
;this way I can view it in a unified IniFolder on my work PC each morning
if printToIniMode
{
iniF := GetPath("MainStatsIniFolder")
iniFkey=%textOrOptions% %text1%
iniFvalue := IniFolderRead(iniF, "", iniFkey)
iniFvalue++
IniFolderWrite(iniF, "", iniFkey, iniFvalue)
}
;print to trace file
if printToTraceMode
{
AddToTrace(textOrOptions, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15)
;Trace2(textOrOptions, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15)
}
return textOrOptions
}
errord(textOrOptions="Hello World!", text1="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text2="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text3="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text4="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text5="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text6="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text7="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text8="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text9="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text10="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text11="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text12="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text13="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text14="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text15="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ")
{
textOrOptions=LOG ERRORD %textOrOptions%
debug(textOrOptions, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15)
return textOrOptions
}
fatalErrord(textOrOptions="Hello World!", text1="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text2="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text3="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text4="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text5="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text6="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text7="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text8="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text9="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text10="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text11="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text12="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text13="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text14="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text15="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ")
{
textOrOptions=FATAL %textOrOptions%
errord(textOrOptions, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15)
ExitApp
}
delog(textOrOptions="Hello World!", text1="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text2="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text3="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text4="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text5="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text6="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text7="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text8="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text9="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text10="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text11="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text12="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text13="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text14="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ", text15="ZZZ-DEFAULT-BLANK-VAR-MSG-ZZZ")
{
textOrOptions=SILENT LOG %textOrOptions%
debug(textOrOptions, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15)
return textOrOptions
}
SelfDestruct()
{
FileDelete(A_ScriptFullPath)
;FileDelete(A_ScriptDir . "\" . A_ScriptName)
}
;TODO ahkFile does NOT support full paths yet.