Advertisement
Najeebsk

NAJEEB-CMD2.ahk

Apr 16th, 2023 (edited)
1,300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*   INFO
  2.    NAJEEB CMD COMMAND UTILITY
  3.    Written by: Najeeb Shah Khan (najeebshahkhan@gmail.com)
  4.    Last Modified: 3-25-2023
  5. */
  6. #Persistent
  7. SetTitleMatchMode, 2
  8. #NoEnv  
  9. ; #Warn  
  10. ;~ SendMode Input
  11. SetWorkingDir %A_ScriptDir%  
  12. FileCreateDir, %A_ScriptDir%\DATA
  13. FileInstall , CMD.txt, %A_ScriptDir%\DATA\CMD.txt, 1
  14. FileInstall , CMD2.ahk, %A_ScriptDir%\DATA\CMD2.ahk, 1
  15. FileInstall , S12.she, %A_ScriptDir%\DATA\S12.she, 1
  16. FileInstall , SkinH_EL.dll, %A_ScriptDir%\DATA\SkinH_EL.dll, 1
  17. FileSetAttrib +HS, %A_ScriptDir%\DATA\S12.she, 2
  18. FileSetAttrib +HS, %A_ScriptDir%\DATA\SkinH_EL.dll, 2
  19. FileSetAttrib +HS, %A_ScriptDir%\DATA\CMD2.ahk, 2
  20. FileSetAttrib +HS, %A_ScriptDir%\DATA\CMD.txt, 2
  21. FileSetAttrib +HS, %A_ScriptDir%\DATA, 2
  22. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  23. ;FileRead,FileContents,CMD.ls
  24. FileRead, MyCMD, %A_ScriptDir%\DATA\CMD.txt
  25. FileRead, FileContents, %A_ScriptDir%\DATA\CMD.txt
  26. Sort, FileContents
  27. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  28. global Folder := A_ScriptDir
  29. global ScriptFolder := A_ScriptDir
  30.  
  31. DetectHiddenWindows,On
  32. Run,%ComSpec% /k,,Hide UseErrorLevel,pid
  33. if not ErrorLevel
  34. {
  35. while !WinExist("ahk_pid" pid)
  36. Sleep,10
  37. DllCall("AttachConsole","UInt",pid)
  38. }
  39. SkinForm(Apply, A_ScriptDir . "\DATA\SkinH_EL.dll", A_ScriptDir . "\DATA\S12.she")
  40. OnExit, GetOut
  41. Gui,Color, 091D33, 091D33
  42. Gui,Font, s14 cDDDDDD, Calibri
  43. Gui,2:Color, 091D33, 091D33
  44. Gui,2:Font, s14 cDDDDDD, Calibri
  45. Gui,Add,Text,X20 Y10, NAJEEB CMD COMMANDS WINDOES
  46. Gui,2:Add,Text,X20 Y10, ALL COMMANDS
  47. Gui,Font, s12 cDDDDDD, Calibri
  48. Gui,Add,Edit,X10 Y40 W600 H500 vText
  49. ;Gui,2:Add,Edit,X2 Y40 W380 H590 vTcmd, %FileContents%
  50. Gui,2:Add, listbox, x2 y40 h555 w380 vresults gClip,
  51. Gui,2:Add,Text,X10 Y602, SEARCH
  52. Gui,2:Add, Edit, x90 y600 w290 vneedle grefresh,
  53. listboxvisible := true
  54. Gui, Add, Button,X10 Y550 gCFloder,Change Folder
  55. Gui, Add, Button,X140 Y550 gSFloder,Start Folder
  56. Gui, Add, Button,X240 Y550 gShowHide vShowHide , Show/Hide More
  57. Gui, Add, Button, X370 Y550 gSave,SAVE TEXT
  58. Gui,Add,Button, X10 Y600 Default gCommand,Command Run
  59. Gui,Add,Edit,X140 Y602 w470
  60. Gui,Show,w620 H620 Autosize, CLI
  61. Gui,2:Show,w420 H620 Autosize, CMD
  62. GuiControl,2:Focus, needle
  63. WinWait, CLI
  64. WinMove, CLI,,5, 10, 620, 670
  65. WinWait, CMD
  66. WinMove, CMD,, 636, 10, 390, 670
  67. Send, {Tab}
  68. Send, {Tab}
  69. Send, {Tab}
  70. Send, {Tab}
  71. return
  72.  
  73. Command:
  74. outvar := ""
  75. Gui, Show
  76. ControlSetText, Edit1
  77. ControlGetText, outvar, Edit2
  78. objShell:=ComObjCreate("WScript.Shell")
  79. ObjShell.CurrentDirectory := Folder
  80. mydir := objShell.CurrentDirectory
  81. CMD := "%ComSpec% /c "outvar
  82. objExec:=objShell.Exec(CMD)
  83. ControlSetText, Edit2, Please wait ...
  84. while,!objExec.StdOut.AtEndOfStream
  85. {
  86. GuiControlGet,Text
  87. strStdOut:=objExec.StdOut.ReadAll()
  88. GuiControl,,Edit1,%Text%`r`n%strStdOut%`r`n%mydir%>
  89. }
  90. objShell:=""
  91. ObjExec:=""
  92. ControlSetText, Edit2
  93. Gui, Show
  94. Return
  95.  
  96.  
  97. CFloder:
  98. ;~ objShell:=ComObjCreate("WScript.Shell")
  99. FileSelectFolder, NewFolder, , 3
  100. If NewFolder =
  101.     MsgBox,,, No Folder selected.,1
  102. Else {
  103. NewFolder := RegExReplace(NewFolder, "\\$")  ; Removes the trailing backslash, if present.
  104. objShell.CurrentDirectory := NewFolder
  105. Folder := NewFolder
  106. ;msgbox, , , Changed folders to %Folder%, 2
  107. }
  108. objShell:=""
  109. ObjExec:=""
  110. ControlSetText, Edit1,  , ahk_exe AutoHotkey.exe
  111. ControlSetText, Edit1, %Folder%>, ahk_exe AutoHotkey.exe
  112. ControlFocus, Edit2, ahk_exe Autohotkey.exe
  113. return
  114.  
  115. SFloder:
  116. ;objShell:=ComObjCreate("WScript.Shell")
  117. Folder := ScriptFolder
  118. ;msgbox, , , Changed folders to %ScriptFolder%, 2
  119. objShell:=""
  120. ObjExec:=""
  121. ControlSetText, Edit1
  122. sleep, 10
  123. ControlSetText, Edit1, %Folder%>, ahk_exe AutoHotkey.exe
  124. ControlFocus, Edit2, ahk_exe Autohotkey.exe
  125. return
  126. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  127. ShowHide:
  128. if hidden {
  129.     GuiControl, 2:Show, CMD
  130.     GuiControl, Show, CLI
  131. }
  132. else {
  133.     GuiControl, 2:Hide, CMD
  134.     GuiControl, Hide, CLI
  135. }
  136. hidden:=not hidden
  137. return
  138. GuiClose:
  139. ButtonCancel:
  140. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  141. Save:
  142. Gui, submit, nohide
  143. FileAppend, `n%Text%, %A_Desktop%\SaveText.txt
  144. return
  145. Refresh:
  146. Gui, Submit, NoHide ; Save the user's input without hiding the window
  147. choicelimit := 0 ; resets the listbox choices counter every time the user adds or removes a letter from the edit box
  148. GuiControl,, results, | ; this empties the previous listbox entries
  149. listbox:="" ; this empties variable that controls the listbox entries
  150. if (needle != "") ; if the user's entry isn't empty (if something typed into editbox)
  151. {
  152. Guicontrol, show, results ; show the listbox
  153. listboxvisible := true
  154. Loop, parse, FileContents, `n, `r ; parse the wordlist.txt in memory to find matches
  155.     {
  156.         haystack:=A_LoopField ; cycles each line 1 by 1 matching 1 word at a time
  157.         position := instr(haystack, needle) ; finds out where the user's entry matches the word at (left, middle, or end of word etc.) or if not at all
  158.         if (position = 1) ;if it matches from the left
  159.         {
  160.                                                 listbox.="|" . haystack ; add it to the listbox variable
  161.             choicelimit := choicelimit + 1 ; increase the counter which counts how many results are going to be in the listbox
  162.         }
  163.     }
  164. Loop, parse, FileContents, `n, `r ; parse the wordlist.txt in memory again for a different kind of matching (midstring match)
  165.     {
  166.         haystack:=A_LoopField ; cycles each line 1 by 1 matching 1 word at a time
  167.         position := instr(haystack, needle) ; finds out where the user's entry matches the word at (left, middle, or end of word etc.) or if not at all
  168.         if (position > 1) ; if it matches anywhere but from the left
  169.         {
  170.                                                 listbox.="|" . haystack ; add it to the listbox variable, importantly AFTER the above matches
  171.             choicelimit := choicelimit + 1 ; increase the counter which counts how many results are going to be in the listbox
  172.         }
  173.     }
  174. if (listbox = "" || listbox = "|") {
  175. listboxvisible := false
  176. return
  177. }
  178. GuiControl,, results, %listbox% ; add the matched words to the listbox entries
  179. GuiControl, choose, results, 1 ; choose the first one by default (highlight it)
  180. resultchosen := 1 ; store which choice is highlighted in a variable
  181. }
  182. Return
  183. Clip:
  184.  Gui, Submit, NoHide
  185.   Clipboard := results
  186. Return
  187. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  188. GetOut:
  189. ;GuiClose:
  190. Gui, Hide
  191. SkinForm(0)
  192. ExitApp
  193. return
  194.  
  195. SkinForm(Param1 = "Apply", DLL = "", SkinName = ""){
  196.     if(Param1 = Apply){
  197.         DllCall("LoadLibrary", str, DLL)
  198.         DllCall(DLL . "\SkinH_AttachEx", AStr,SkinName, Str,"mhgd")
  199.     }else if(Param1 = 0){
  200.         DllCall(DLL . "\USkinExit")
  201.         }
  202. }
  203. ;=-=-=-=-=-=-=-=-=-=- END SCRIPT -=-=-=-=-=-=-=-=-=-=-=-
  204. #R::Reload
  205. #S::Suspend
  206. #P::Pause
  207. ESC::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement