Advertisement
Guest User

Untitled

a guest
Jan 31st, 2019
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. #SingleInstance Force
  3. SendMode Input
  4. SetWorkingDir %A_ScriptDir%
  5.  
  6. ;ini file generation / read section for options.
  7. Start:
  8. If !FileExist(A_APPDATA "\AutoTyper")
  9.     {
  10.     FileCreateDir, %A_APPDATA%\AutoTyper
  11.     If ErrorLevel
  12.         {
  13.         Msgbox, Something went wrong with creating the folder %A_APPDATA%\AutoTyper`n`nAutoTyper will use defaults instead. Configuration not available.
  14.         }
  15.     }
  16. If !FileExist(A_APPDATA "\AutoTyper\Settings.ini")
  17.     {
  18.     IniWrite, 15, %A_APPDATA%\AutoTyper\Settings.ini, General, MaxNumRows
  19.     If ErrorLevel
  20.         {
  21.         Msgbox, Something went wrong with creating or writing the settings.ini file in %A_APPDATA%\AutoTyper`n`nAutoTyper will use defaults instead. Configuration not available.
  22.         }
  23.     MaxNumRows = 15
  24.     IniWrite, ^1, %A_APPDATA%\AutoTyper\Settings.ini, General, Hotkey
  25.     If ErrorLevel
  26.         {
  27.         Msgbox, Something went wrong with creating or writing the settings.ini file in %A_APPDATA%\AutoTyper`n`nAutoTyper will use defaults instead. Configuration not available.
  28.         }
  29.     GuiHotkey = ^1
  30.     } else {
  31.     IniRead, MaxNumRows, %A_APPDATA%\AutoTyper\Settings.ini, General, MaxNumRows, 15
  32.     IniRead, GuiHotkey, %A_APPDATA%\AutoTyper\Settings.ini, General, Hotkey, ^1
  33.     }
  34. Hotkey, %GuiHotkey%, Begin
  35. return
  36.  
  37. ;config section
  38. CONFIG:
  39. Hotkey, %GuiHotkey%, Begin, Off
  40. gui, destroy
  41. gui, font, bold
  42. gui, add, text,, Config Section:
  43. gui, font
  44. gui, add, text,, Hotkey for gui (default CTRL-1):
  45. gui, add, hotkey, vGuiHotkey, %GuiHotkey%
  46. gui, add, text,, Max number of rows per column`n(default 15)
  47. gui, add, edit, vMaxNumRows, %MaxNumRows%
  48. gui, add, button, gConfigOK section, OK
  49. gui, add, button, gConfigReset ys, RESET
  50. gui, show
  51. return
  52.  
  53. CONFIGOK:
  54. gui, submit
  55. gui, destroy
  56. IniWrite, %GuiHotkey%, %A_APPDATA%\AutoTyper\Settings.ini, General, Hotkey
  57. IniWrite, %MaxNumRows%, %A_APPDATA%\AutoTyper\Settings.ini, General, MaxNumRows
  58. reload
  59. ExitApp
  60.  
  61. CONFIGRESET:
  62. FileRemoveDir, %A_APPDATA%\AutoTyper, 1
  63. reload
  64. ExitApp
  65.  
  66. ;Hotkey element
  67. Begin:
  68. Hotkey, %GuiHotkey%, Begin, Off
  69. ;capture old clipboard to attempt to put it back
  70. OldClipboard := clipboard
  71. WinGetActiveTitle, WinTitle
  72.  
  73. ;init arrays
  74. FileArray:= []
  75. FileNameArray:= []
  76. FolderArray := []
  77.  
  78. ;define standard gui top section
  79. Gui,+AlwaysOnTop
  80. gui, add, text, x1 y1 section, Pasting into %WinTitle%
  81. gui, add, text,, Press OK or Enter after choosing a selection below
  82. gui, add, button, gOK default ys, OK - PASTE
  83. gui, add, button, gCONFIG y+1, CONFIG
  84.  
  85. ;enumerate .txt files in Script Directory
  86. Loop, Files, %A_ScriptDir%\*.txt, R
  87.     {
  88.     FileNameArray.Push(A_LoopFileLongPath)
  89.     StringReplace, FileName, A_LoopFileName, .txt
  90.     FileArray.Push(FileName)
  91.     StringReplace, FolderName, A_LoopFileDir, %A_ScriptDir%\
  92.     FolderArray.Push(FolderName)
  93.     }
  94.    
  95. ;begin pushing files into dynamic gui
  96. CurFolder =
  97. NumFilesCol = 0
  98. If (!FileArray.MaxIndex()) ;handle zero files
  99.     {
  100.     gui, font, bold
  101.     gui, add, text, x2 y55 section, No .txt Files in script Folder!
  102.     gui, font
  103.     }
  104. For index, file in FileArray
  105.     {
  106.     NumFilesCol += 1
  107.     Filenum := A_Index
  108.     ;if the folder of the next file has changed, create a new bold category.
  109.     If (FolderArray[A_Index] <> CurFolder)
  110.         {
  111.         CurFolder := FolderArray[A_Index]
  112.         FolderCount = 0
  113.         For Indexb, folder in FolderArray
  114.             ;count number of files in the folder, according to array
  115.             {
  116.             If (CurFolder = folder)
  117.                 {
  118.                 FolderCount += 1
  119.                 }
  120.             }
  121.         If (NumFilesCol + FolderCount > MaxNumRows) or (NumFilesCol > MaxNumRows)
  122.             {
  123.             ;if this file is of a new folder, and there's too many files in it to fit in
  124.             ;NumFilesCol (default 15), create a new column (ys)
  125.             gui, font, bold
  126.             gui, add, text, ys, %CurFolder%
  127.             NumFilesCol = 0
  128.             gui, font
  129.             } else if (Filenum = 1) {
  130.             ;if it is the first option, create a new section of gui
  131.             If (CurFolder = A_ScriptDir) ;handle no folders
  132.                 {
  133.                 gui, font, bold
  134.                 gui, add, text, x2 y55 section, Files
  135.                 gui, font
  136.                 }
  137.                 else
  138.                 {
  139.                 gui, font, bold
  140.                 gui, add, text, x2 y55 section, %CurFolder%
  141.                 gui, font
  142.                 }
  143.             } else {
  144.             ;if this file is of a new folder but doesn't exceed NumFilesCol (def 15)
  145.             ;don't create a new column.
  146.             gui, font, bold
  147.             gui, add, text,, %CurFolder%
  148.             gui, font
  149.             }
  150.         }
  151.     If NumFilesCol > MaxNumRows
  152.         ;if for some reason the file is exceeding NumFilesCol, put it on a new column
  153.         {
  154.         gui, add, checkbox, ys vV%index%, %file%
  155.         } else {
  156.         gui, add, checkbox, vV%index%, %file%
  157.         }
  158.     }
  159.    
  160. ;show gui, wait for input
  161. gui, show
  162. return
  163. OK:
  164. ButtonOK:
  165. Gui, Submit
  166. Gui, Destroy
  167. Goto Next
  168.  
  169. ;gui close, do not submit vars
  170. GuiClose:
  171. GuiEscape:
  172. clipboard := OldClipboard
  173. Hotkey, %GuiHotkey%, Begin, On
  174. Gui, Destroy
  175. Goto Start
  176.  
  177. ;pasting from files, loop through the total entries in enumerated files
  178. ;if variable V# is 1, read from file related to that index # num and paste with simple ctrl-v
  179. Next:
  180. clipboard =
  181. Loop, % FileArray.MaxIndex()
  182.     {
  183.     If V%a_index% = 1
  184.         {
  185.         FileRead, FileContent, % FileNameArray[A_Index]
  186.         clipboard := FileContent
  187.         ClipWait, 2
  188.         If ErrorLevel
  189.             {
  190.                 MsgBox, The attempt to copy text onto the clipboard failed.
  191.                 clipboard := OldClipboard
  192.                 return
  193.             }
  194.         break
  195.         }
  196.     }
  197.    
  198. WinActivate, %WinTitle%
  199. WinWaitActive, %WinTitle%
  200. Send ^v
  201. ;sleep because the clipboard action below can actually run before the ^v input is fully sent due to keydelay!
  202. sleep 1
  203.  
  204. ;clean up variables to allow changes and prevent accidental transferral of variable contents between
  205. ;pasting uses.
  206. For index, file in FileArray
  207.     {
  208.     V%index% = 0
  209.     }
  210. clipboard := OldClipboard
  211. Hotkey, %GuiHotkey%, Begin, On
  212. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement