-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathFunctions.ahk
More file actions
258 lines (222 loc) · 5.33 KB
/
Copy pathFunctions.ahk
File metadata and controls
258 lines (222 loc) · 5.33 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
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
#Include %A_ScriptDir%\lib\GUID.ahk
#Include %A_ScriptDir%\lib\Process.ahk
#Include %A_ScriptDir%\lib\ClipboardHelpers.ahk
#Include %A_ScriptDir%\lib\Fade.ahk
#Include %A_ScriptDir%\lib\AHKPanic.ahk
#Include %A_ScriptDir%\lib\DynaRun.ahk
#Include %A_ScriptDir%\lib\MoveTaskbar.ahk
#Include %A_ScriptDir%\lib\Varize.ahk
#Include %A_ScriptDir%\lib\DBGView.ahk
#Include %A_ScriptDir%\lib\Json.ahk
CreateStartupShortcut()
{
SplitPath, A_ScriptName, , , , OutNameNoExt
LinkFile := A_Startup "\" OutNameNoExt ".lnk"
IfNotExist, %LinkFile%
{
FileCreateShortcut, %A_ScriptFullPath%, %LinkFile%
Notify("Startup Shortcut Created.","",-3,"Style=Alert")
}
}
CheckAdmin()
{
If ! A_IsAdmin
{
MsgBox, 0x34,%A_ScriptName%, Missing Admin Privileges!`n`nWould you like to continue?
IfMsgBox No
{
SplitPath, A_AhkPath,, A_AhkDir
Run % A_AhkDir
ExitApp
}
SplitPath, A_AhkPath,, A_AhkDir
Run % A_AhkDir
}
}
Edit(file, editorPath) ; Refocuses Sublime if file is opened while focused
{
Run %editorPath% %file%
Sleep 50
WinActivate, ahk_class PX_WINDOW_CLASS
}
LoggedIn()
{
if WinExist("A")
return true
else
return false
}
WinWaitText(search, window, windowtext, timeout=10000, interval=50)
{
loops := timeout / interval
Loop %loops%
{
WinGetText, thetext, %window%, %windowtext%
if RegExMatch(thetext, search)
break
Sleep, %interval%
}
}
RunProgFiles(exe)
{
ProgramFiles86 := "C:\Program Files (x86)"
If FileExist(A_ProgramFiles "\" exe)
Run % A_ProgramFiles "\" exe
else If FileExist(ProgramFiles86 "\" exe)
Run % ProgramFiles86 "\" exe
else
ErrorLevel = 1
}
LockWorkstation(screenOff = 0)
{
Run, %A_WinDir%\System32\rundll32.exe user32.dll`, LockWorkStation
if (screenOff = 1)
{
Sleep 1000
SendMessage, 0x112, 0xF170, 2,, Program Manager
}
Return
}
UserName(username)
{
Return % (A_Username = %username%) ? 1 : 0
}
AtWork()
{
Return % (A_Username = "elliotd") ? 1 : 0
}
MouseIsOver(Wintitle) {
MouseGetPos,,, Win
return WinExist(Wintitle . " ahk_id " . Win)
}
MouseIsOverClass(WinClass) {
MouseGetPos,,,win
WinGetClass,class,ahk_id %win%
return (class = winClass)
}
MouseIsOverControl(winControl)
{
MouseGetPos, , , , Control
return (Control = winControl)
}
ActiveControlIsOfClass(Class)
{
ControlGetFocus, FocusedControl, A
ControlGet, FocusedControlHwnd, Hwnd,, %FocusedControl%, A
WinGetClass, FocusedControlClass, ahk_id %FocusedControlHwnd%
return (FocusedControlClass=Class)
}
IsOnline(machine)
{
IfExist, \\%machine%\c$
return 1
else
return 0
}
Cl(command, hide = 1)
{
if hide
RunWait, %comspec% /c "%command%",, Hide
Else
Run, %comspec% /c %command%
}
IsFocusOn(current)
{
ControlGetFocus, OutputVar, A
IfEqual, current, %OutPutVar%
return 1
else
return 0
}
StringReplace(string, find, replace="")
{
Stringreplace, string, string, % find, % replace, All
return string
}
RegInStr(haystack, needle)
{
return % If Instr(RegExReplace(haystack, needle, "foundit!"), "foundit!") ? 1 : 0
}
Log(text, file = "debug.log")
{
FormatTime, Now,, `nM/dd [h:mm]
FileAppend, %Now%`t%text%, %file%
}
CreateXCut(path, shortcut, name)
{
If FileExist(path)
{
FileCreateShortcut, %path%, %shortcut%, C:\, "%A_ScriptFullPath%", %name%
msgbox, exists
}
Else
Msgbox, File Does Not Exist!
}
RxMatch(string, pattern)
{
return % Substr(string, RegExMatch(string, "P)" pattern, matchlength), matchlength)
}
StrFmt(string, zero, one = "", two = "", three = "", four = "", five = "")
{
return StringFormat(string, zero, one, two, three, four, five)
}
StringFormat(string, vargs*)
{
for each, varg in vargs
StringReplace,string,string,`%s, % varg
return string
}
RunIfExist(exe, response = 0)
{
If FileExist(exe)
Run "%exe%"
Else
{
If response = 0
return
Else If response = 1
msgbox, %exe% does not exist.
}
}
UpFolder(folder, numberUp = 1)
{
; Count available directories
DirCount := 0
Loop, Parse, folder, \
{
if (StrLen(A_LoopField) > 0)
{
FolderArray%A_Index% = %A_Loopfield%
DirCount++
}
}
; Check if file or folder and adjust DirCount
If (IsFile(folder))
numberUp++
; Not enough folders to go that high
if (numberUp + 1 > DirCount)
{
ErrorLevel := 1
return ""
}
; Calculate how far to go up
DirCount := DirCount - numberUp
; Generate output dir
OutDir := ""
Loop, %DirCount%
{
dir := FolderArray%A_Index%
OutDir .= dir
if (A_Index != DirCount)
OutDir .= "\"
}
return OutDir
}
IsFolder(fileOrFolder)
{
return InStr( FileExist(fileOrFolder), "D" ) ? 1 : 0
}
IsFile(fileOrFolder)
{
return InStr( FileExist(fileOrFolder), "D" ) ? 0 : 1
}