· 7 years ago · Feb 07, 2019, 05:36 PM
1#Include C:\Users\cody.jones\Documents\Autohotkey\Lib\Json.ahk
2
3;;
4;; Variables for GoLive Kit
5;;
6isActive := false
7activeSequence := false=
8url_half =: "/hr/employer_page_snippets/%index%/edit"
9;8000 := 8000
10global vProd := ""
11global vSand := ""
12
13
14;;
15;; Variables for BuilderLoader
16;;
17file_data := []
18file_data[1] := "Id,Position Number,Random Value`r`n1,FA7263,Teri`r`n"
19file_data[2] := "Id,Value,Position,Disabled`r`n1,Answer Bank Item, 1, `r`n"
20file_data[3] := "{`r`n`t""project"": ""{PRJ_FOLD}"",`r`n`t""validation_only"": ""true"",`r`n`t""field"": {`r`n`t`t ""field1"": ""lookup_example_val_id""`r`n`t },`r`n`t ""table"": {`r`n`t`t ""field1"": ""job_duties_attributes""`r`n`t },`r`n`t""Data"": {`r`n`t`t ""Staff.csv"": {`r`n`t`t`t""Identifier"": ""Position Number"",`r`n`t`t`t""Position_Type"": 1`r`n`t`t }`r`n`t},`r`n`t""AnswerBank"": {`r`n`t`t ""AnswerBank.csv"": {`r`n`t`t`t""Field_Name"": ""lookup_example_val_id""`r`n`t`t }`r`n`t}`r`n}`r`n"
21
22
23;;
24;; BuilderLoader Definitions
25;;
26Explorer_GetWindow(hwnd="")
27{
28 ; thanks to jethrow for some pointers here
29 WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
30 WinGetClass class, ahk_id %hwnd%
31
32 if (process!="explorer.exe")
33 return
34 if (class ~= "(Cabinet|Explore)WClass")
35 {
36 for window in ComObjCreate("Shell.Application").Windows
37 if (window.hwnd==hwnd)
38 return window
39 }
40 else if (class ~= "Progman|WorkerW")
41 return "desktop" ; desktop found
42}
43
44Explorer_GetPath(hwnd="")
45{
46 if !(window := Explorer_GetWindow(hwnd))
47 return ErrorLevel := "ERROR"
48 if (window="desktop")
49 return A_Desktop
50 path := window.LocationURL
51 path := RegExReplace(path, "ftp://.*@","ftp://")
52 StringReplace, path, path, file:///
53 StringReplace, path, path, /, \, All
54
55 ; thanks to polyethene
56 Loop
57 If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
58 StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
59 Else Break
60 return path
61}
62
63PathBuilder(path, name, folder) {
64 output := Format("{1}\{2}\{3}",path,name,folder)
65 return %output%
66}
67
68Create_Builder_Project(name, dir) {
69 global file_data
70 path := dir
71 if(path == "")
72 return False
73
74 my_paths := ["", "Data", "Input", "Data\AnswerBank"]
75
76 file_create := [ "Data\Staff.csv", "Data\AnswerBank\AnswerBank.csv", "config.json" ]
77
78 for index, element in my_paths {
79 dir := PathBuilder(path, name, element)
80 FileCreateDir, %dir%
81
82 }
83 val := path
84 word_array := StrSplit(path, "\Project")
85 proj_name := % "Project" word_array[2] "\" name
86
87 proj_name := StrReplace(proj_name, "\" , "\\", c_val)
88
89 for index, element in file_create {
90 dir := PathBuilder(path, name, element)
91 CreateFile(dir, file_data[index], proj_name)
92 }
93 return True
94
95}
96
97CreateFile(filename, write, proj_folder = "") {
98if (FileExist(filename))
99 FileDelete, filename
100
101file := FileOpen(filename, "w")
102
103raw_text = % write
104if(proj_folder != "") {
105 StringReplace, outvar, raw_text, {PRJ_FOLD} , %proj_folder%
106 raw_text := outvar
107 }
108file.Write(raw_text)
109file.Close()
110
111}
112
113CloseTab(Title)
114{
115 WinActivate, %Title%
116 Send ^w
117}
118
119GetGoLiveData() {
120
121 global
122 Gui, -Resize -MaximizeBox
123 Gui, Margin, 100, 50
124 Gui, Color, EEAA99
125 gui, font, s10, Verdana
126 Gui, Add, Text,, Production:
127 Gui, Add, Text,, Sandbox:
128 Gui, Add, Text,, Index Difference:
129 Gui, Add, Edit, vProd ym ; The ym option starts a new column of controls.
130 Gui, Add, Edit, vSand
131 Gui, Add, Edit, vIndex, 0
132 Gui, Add, Button, x250, Ok ; The label ButtonOK (if it exists) will be run when the button is pressed.
133 Gui, Show,, Simple Input Example
134 return
135 GuiClose:
136 Gui, Cancel
137 return
138
139 ButtonOK:
140 Gui, Submit
141 Sleep, 3500
142 FileRead, JSONtext, %A_ScriptDir%\AutoHotkey\Data\Data.json
143 jsonv = %JSONtext%
144 parsed := JSON.Load(jsonv)
145
146 For k, v in parsed
147 CopyPage(k, v, Sand, Prod, Index)
148 return
149
150 MsgBox, Data Load Completed!
151
152}
153
154CopyPage(index, value, url_prefix, prod_prefix, indexdiff)
155{
156 newIndex := index + indexdiff
157 url = %url_prefix%/hr/employer_page_snippets/%index%/edit
158 Run, chrome.exe %url%
159
160 Sleep 3500
161 WinGetTitle, Title, A
162 clipboard = ;
163 send {TAB}{TAB}{TAB}
164 send ^a
165 send ^c
166 Sleep 3500
167
168 WinActivate, %Title%
169 CloseTab(Title)
170 Sleep 1000
171
172 UpdatePage(newIndex, value, prod_prefix)
173}
174
175UpdatePage(index, value, prod_prefix)
176{
177 url = %prod_prefix%/hr/employer_page_snippets/%index%/edit
178 Run, chrome.exe %url%
179 Sleep 3500
180 WinGetTitle, Title, A
181
182 send {TAB}{TAB}{TAB}
183 send ^a
184 send ^v
185 send {TAB}{ENTER}
186 Sleep 3500
187
188 WinActivate, %Title%
189 CloseTab(Title)
190 Sleep 1000
191}
192
193
194
195
196;;
197;; Active Sequence - ctrl+= : Activate Sequence
198;; - 1 : Pressing 1 Initiates GoLive Functions
199;; - = : Run Go Live
200;;=
201
202^=::
203activeSequence := true
204
205return
206
207
208$1::
209if (activeSequence = true)
210{
211 MsgBox, Automated GoLive Activated!
212 isActive := true
213 activeSequence = false
214}
215else
216{
217Send {1}
218}
219
220return
221
222$=::
223if (isActive = true)
224{
225
226 ;InputBox, Prod , "Production Site", "Enter URL"
227 ;InputBox, Sand , "Sandbox Site", "Enter URL"
228 GetGoLiveData()
229 isActive := false
230
231 ;filename = %A_ScriptDir%\AutoHotkey\Data\MyFile.json
232 ;CreateFile(filename,jsonv)
233
234}
235else
236{
237Send {=}
238}
239
240return
241
242;;
243;; Builder Project - ctrl+N : Create Project Format in Current Folder
244;; - ctrl+R : Run Builder Project
245;;
246
247$^n::
248
249if WinActive("ahk_exe explorer.exe") {
250 InputBox, UserInput, Project Name, Please enter the name of the school
251 if ErrorLevel
252 MsgBox, CANCEL was pressed.
253 else {
254 path := Explorer_GetPath()
255 word_array := StrSplit(path, "\Project").MaxIndex()
256 if(UserInput != "" and path != "ERROR") {
257 if(word_array > 1) {
258 Create_Builder_Project(UserInput, path)
259 }
260 else
261 MsgBox, "Can only create projects within the Project Folder"
262
263 }
264 else
265 MsgBox, "Error Building Project Try Again"
266
267 }
268}
269else {
270 ;MsgBox, Not In Explorer
271 Send ^n
272 }
273
274return
275
276
277$^r::
278if WinActive("ahk_exe explorer.exe") {
279 Run, "C:\Users\cody.jones\Desktop\Builder Release\Run.bat"
280}
281else {
282 Send ^r
283 }
284return
285
286
287;;
288;; Personal Hotkeys - ctrl+Q : Type my GoToMeeting URL
289;; - ctrl+alt+Q : Open Slack, Open Mail, Open Fuze
290;; - ctrl+alt+- : Draw Long Line Seperator
291;;
292
293^q::
294send https://www.gotomeet.me/CodyJonesPA
295;send ^c
296return
297
298^!-::
299send ______________________________________________________________________________
300send {Enter}{Enter}{Enter}
301
302return
303
304`::
305Run, "C:\Users\cody.jones\Desktop\Knowledge Base"
306return
307
308^g::
309;Run, "C:\Program Files\GIMP 2\bin\gimp-2.10.exe"
310Run,%windir%\system32\StikyNot.exe
311Sleep, 200
312WinActivate, Sticky Note
313return
314
315^!q::
316IfWinNotExist Slack - PeopleAdmin
317 RunWait, slack.exe, C:\Users\cody.jones\AppData\Local\slack\, Min
318IfWinNotExist Inbox - cody.jones@peopleadmin.com - Outlook
319 RunWait, "Outlook 2016.lnk", C:\ProgramData\Microsoft\Windows\Start Menu\Programs
320IfWinNotExist Fuze
321 RunWait, Fuze.exe, C:\Users\cody.jones\AppData\Local\FuzeBox\Fuze\, Min