Advertisement
Guest User

batch topic search script

a guest
Jun 21st, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. #Requires AutoHotkey v2.0
  2.  
  3. topicsFile := "topics.txt"
  4. lastTopicFile := "last_topic.txt"
  5.  
  6. topics := []
  7.  
  8. ^!s:: { ; Ctrl + Alt + S
  9. inputObj := MultilineInput("Batch Topic Search", "Enter one query per line:")
  10. if !inputObj || inputObj.queries = ""
  11. return
  12.  
  13. WinActivate("ahk_exe msedge.exe")
  14.  
  15. queries := StrSplit(inputObj.queries, "`n")
  16. topic := inputObj.topicCode
  17.  
  18. for query in queries {
  19. cleanQuery := Trim(query)
  20. if cleanQuery = ""
  21. continue
  22.  
  23. Run("msedge.exe --new-tab edge://newtab/") ; Launch Edge or open a new tab
  24. WinWaitActive("ahk_exe msedge.exe", , 5)
  25.  
  26. Sleep(300) ; Wait a bit to ensure tab is ready
  27. Send(cleanQuery . " " topic)
  28. Sleep(50)
  29. Send("{Enter}")
  30. Sleep(50)
  31. }
  32. total := queries.Length
  33. if total > 1 {
  34. Sleep(100)
  35. Loop total - 2 {
  36. Send("^+{Tab}") ; Ctrl+Shift+Tab to move left
  37. Sleep(50)
  38. }
  39. }
  40. }
  41.  
  42. LoadTopics(default := "Blender") {
  43. global topicsFile
  44. if !FileExist(topicsFile) {
  45. SaveTopics(default)
  46. return default
  47. }
  48. content := FileRead(topicsFile)
  49. return StrSplit(Trim(content), "|")
  50. }
  51.  
  52. SaveTopics(topicList) {
  53. global topicsFile
  54. File := FileOpen(topicsFile, "w", "UTF-8")
  55. joinedTopics := ""
  56. for i, topic in topicList {
  57. joinedTopics .= topic . (i = topicList.Length ? "" : "|")
  58. }
  59. if File {
  60. File.Write(joinedTopics)
  61. File.Close()
  62. }
  63. }
  64.  
  65. SaveLastTopic(topic) {
  66. File := FileOpen(lastTopicFile, "w", "UTF-8")
  67. if File {
  68. File.Write(topic)
  69. File.Close()
  70. }
  71. }
  72.  
  73. LoadLastTopic(default := "Blender") {
  74. if FileExist("last_topic.txt") {
  75. topic := Trim(FileRead("last_topic.txt"))
  76. return topic != "" ? topic : default
  77. }
  78. return default
  79. }
  80.  
  81. MultilineInput(title := "Input", prompt := "Enter text:") {
  82. global topics := LoadTopics()
  83.  
  84. ih := InputHook("L1 V", "{Enter}{Escape}")
  85. ih.KeyOpt("{Enter}", "N") ; Don’t auto-complete on Enter
  86. ih.KeyOpt("{Escape}", "N") ; Don’t auto-complete on Escape
  87.  
  88. result := ""
  89. topic := ""
  90.  
  91. myGui := Gui("+AlwaysOnTop +ToolWindow", title)
  92. myGui.SetFont("s10")
  93. myGui.Add("Text",, prompt)
  94.  
  95. edit := myGui.Add("Edit", "r10 w400 vInputEdit WantTab") ; WantTab allows Tab chars
  96.  
  97. myGui.Add("Text",, "Topic:")
  98.  
  99. defaultTopic := LoadLastTopic()
  100. defaultIndex := 1
  101. for i, topic in topics {
  102. if (topic = defaultTopic) {
  103. defaultIndex := i
  104. break
  105. }
  106. }
  107.  
  108. ddl := myGui.Add("DropDownList", "vTopicDDL Choose" defaultIndex, topics)
  109.  
  110. removeBtn := myGui.Add("Button", "x+10 yp w150", "Remove Selected")
  111.  
  112. myGui.Add("Text", "XM", "New Topic:")
  113. newTopicInput := myGui.Add("Edit", "x+10 yp w200 vNewTopicInput")
  114. addBtn := myGui.Add("Button", "x+10 yp w80", "Add Topic")
  115. addBtn.OnEvent("Click", AddNewTopic)
  116. AddNewTopic(btn, info) {
  117. newTopic := Trim(newTopicInput.Value)
  118. if newTopic = ""
  119. return
  120.  
  121. for topic in topics
  122. if newTopic = topic
  123. return
  124.  
  125. topics.Push(newTopic)
  126. SaveTopics(topics)
  127.  
  128. ddl.Delete()
  129. ddl.Add(topics)
  130. ddl.Value := topics.Length ; Select the new one
  131. newTopicInput.Value := "" ; Clear the input box
  132. }
  133.  
  134. removeBtn.OnEvent("Click", RemoveTopic)
  135. RemoveTopic(btn, info) {
  136. if topics.Length = 0 {
  137. return
  138. }
  139. topics.RemoveAt(ddl.Value)
  140.  
  141. SaveTopics(topics)
  142.  
  143. ddl.Delete()
  144. ddl.Add(topics)
  145. if topics.Length = 0 {
  146. return
  147. }
  148. ddl.Value := 1
  149. }
  150.  
  151. myGui.Show()
  152.  
  153. Loop {
  154. ih.Start()
  155. ih.Wait()
  156.  
  157. if ih.EndKey = "Escape" {
  158. result := ""
  159. break
  160. } else if ih.EndKey = "Enter" {
  161. if !GetKeyState("Shift", "P") {
  162. result := edit.Value
  163. selectedTopic := ddl.Text
  164. break
  165. }
  166. }
  167. }
  168.  
  169. selectedTopic := ddl.Text
  170. SaveLastTopic(selectedTopic)
  171.  
  172. myGui.Hide()
  173. myGui.Destroy()
  174.  
  175. return { queries: result, topicCode: selectedTopic}
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement