SHARE
TWEET

ScriptParserV4.ahk

coffeeAnon Mar 17th, 2020 (edited) 529 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Function:
  2. ; Copies lines from a notepad-like text editor to your clipboard and pastes them into a program of your choice.
  3. ; detailed feature description will be displayed during the setup
  4. ; too lazy to write the setup for the hotkey, so just edit this with any text editor and search for F3:: with lots of ";" next to it. that's what you want to change
  5.  
  6. #NoEnv  
  7. SendMode Input
  8. SetWorkingDir %A_ScriptDir%
  9. #Persistent
  10. #singleinstance force
  11.  
  12. ;#include debug.ahk
  13. ;gui,log:show
  14.  
  15. ; to avoid calling a nonexistent function when debug.ahk isn't available
  16. debug(str) {
  17. }
  18.  
  19.  
  20. ini = ScriptParser.ini
  21.  
  22. if not FileExist(ini){
  23.     debug("file " ini " not found")
  24.     iniwrite,dummy,%ini%,editors,imageEditor
  25.     iniwrite,dummy,%ini%,editors,textEditor
  26. }
  27.  
  28. IniRead,image,%ini%,editors,imageEditor
  29. IniRead,text,%ini%,editors,textEditor
  30. IniRead,firststartup,%ini%,first,first
  31.  
  32.  
  33. if (firststartup = "ERROR") {
  34.     msgbox,0,%A_ScriptName% Function,Copies lines from a notepad-like text editor to your clipboard.`n`n-lines can begin with or without a "[speaker]: " designation`n`n-if a "[speaker]: " designation was used, the "[speaker]" will be displayed as a tooltip.`nA "[speaker]" generally isn't supposed to have spaces in it, as that results in unpredictable behaviour, however it accepts any "[speaker]s" with only one letter after the first space or ONLY numbers after the first space. anything else will be treated as a line with no "[speaker]:" and copied directly to the clipboard.`n`n-lines consisting solely of "-" will be counted as pagebreaks and not copied to the clipboard`n`n-anything enclosed in "[ ]" will not be copied to the clipboard but will also break the parsing loop (meaning you'll have to press the hotkey again to advance further).`n`n-anything after a "#" will be counted as a comment and not copied to the clipboard, instead it will displayed as a tooltip. A line consisting only of a comment will display the comment and break the parsing loop.
  35.     iniwrite,0,%ini%,first,first
  36. }
  37.  
  38. if (image = "dummy" ) or (text = "dummy" ) {
  39.     msgbox ini file has incomplete configuration.`nSetup required.`nPlease press [Ok] and follow the instructions
  40.     gui,setI:new,,Set Image Editor
  41.     gui,setI:Margin,5,5
  42.     gui,setI: +AlwaysOnTop
  43.     gui,setI:add,text,,open your prefered image editor and place the window in an`neasily accessible location.`nThen press OK and proceed to click on the window of your`nimage editor
  44.     gui,setI:add,button, w80 x215 gSetImageEditor, Ok
  45.     gui,setI:show,w300
  46. }
  47.  
  48. global TextEditor := text
  49. global ImageEditor := image
  50.  
  51. return
  52.  
  53.  
  54. #if winactive("ahk_exe " . ImageEditor) or winactive("ahk_exe " . TextEditor) and WinExist("ahk_exe " . TextEditor) and WinExist("ahk_exe " . ImageEditor)
  55. F3:: ;;;;;;;;;;;hotkey for this action. for modifier keys use: Ctrl->^, Alt->!, Shift->+. Example: Shift+Q -> +q:: ;;;;;;;;;;;;;;
  56. ;SoundBeep
  57. debug("// script parser activated")
  58. ScriptParser()
  59. return
  60.  
  61.  
  62. +F3::
  63. failsafe := 0
  64. ignore := 0
  65. debug(prevPage activated)
  66. prevPage()
  67. return
  68. #if
  69.  
  70. prevPage() {
  71.     nextline:
  72.     if (failsafe >= 30)
  73.     if (ignore != 1) {
  74.         msgbox,4,,advanced %failsafe% times without finding start of page. Continue?
  75.             ifmsgbox,Yes
  76.                 ignore := 1
  77.             ifmsgbox,No
  78.                 return
  79.     }
  80.     mousegetpos, x, y
  81.     tooltip,going to top of page,x-80,y+10
  82.     SetTimer,tt,-1000
  83.     Clipboard := ""
  84.     WinActivate % "ahk_exe " textEditor
  85.     sleep 1
  86.     send,{up}{Home}
  87.     sleep 1
  88.     Send,{Home}+{End 4} ; home sets cursor to start of line, +End holds shift and moves cursor to end of line
  89.     sleep 1
  90.     Send,{CtrlDown}{c}{CtrlUp} ; copies the selected line
  91.     sleep 1
  92.     string := Clipboard
  93.    
  94.     stringright, last, string, 1
  95.     If (last = "-") {
  96.         return
  97.     }
  98.     else {
  99.         goto,nextline
  100.     }
  101. }
  102.  
  103. ScriptParser()
  104. {
  105.     next:
  106.     failsafe += 1
  107.     if (failsafe >= 15)
  108.         if (ignore != 1) {
  109.             msgbox,4,,advanced %failsafe% times without finding a new line of text. Continue?
  110.                 ifmsgbox,Yes
  111.                     ignore := 1
  112.                 ifmsgbox,No
  113.                     return
  114.         }
  115.     Clipboard := ""
  116.     WinActivate % "ahk_exe " textEditor
  117.     ;soundbeep,100
  118.     Send,{Home}+{End 4} ; home sets cursor to start of line, +End holds shift and moves cursor to end of line
  119.     sleep 1
  120.     Send,{CtrlDown}{c}{CtrlUp} ; copies the selected line
  121.     sleep 1
  122.     Send,{Down}{Home} ; go to start of next line
  123.     sleep 1
  124.     if InStr(Clipboard,"#") {
  125.         commentless := StrSplit(Clipboard,"#",,2)
  126.         string := commentless[1]
  127.     }
  128.     else {
  129.         string := Clipboard
  130.     }
  131.  
  132.     Lsplit := lineSplit(Clipboard)
  133.    
  134.     if (Lsplit = "") {
  135.         debug("empty string, advancing")
  136.         mousegetpos, x, y
  137.         tooltip,empty,x-80,y+10
  138.         SetTimer,tt,-1000
  139.         goto, next
  140.     }
  141.     else if ( RegExMatch(Clipboard,"\[.*\]$") ) {
  142.         mousegetpos, x, y
  143.         tooltip,%Clipboard%,x-80,y+10
  144.         SetTimer,tt,-2000
  145.         return
  146.     }
  147.     Clipboard := ""
  148.    
  149.     debug("copied string: " string)
  150.    
  151.     global stringArray := StrSplit(string," ",,2)
  152.     debug(StringArray[1] " " StringArray[2])
  153.    
  154.     if InStr(stringArray[1],":") {
  155.         debug("column found " stringArray[1])
  156.        
  157.         if (stringArray[2]) {
  158.             debug(stringArray[2])
  159.             string := stringArray[2]
  160.             index1 := stringArray[1]
  161.             mousegetpos, x, y
  162.             tooltip,%index1%,x-80,y+10
  163.             SetTimer,tt,-1000
  164.         }
  165.         else {
  166.             debug("index 2 empty")
  167.             goto, next
  168.         }
  169.     }
  170.         ; this one's for "girl a:" / "girl 1:" etc
  171.     else if RegExMatch(stringArray[2],"^.{1}:") {
  172.         debug(stringArray[2])
  173.         subarray := StrSplit(stringArray[2],": ",,2)
  174.         string := subarray[2]
  175.         index1 := stringArray[1] " " subArray[1]
  176.         mousegetpos, x, y
  177.         tooltip,%index1%,x-80,y+10
  178.         SetTimer,tt,-1000
  179.     }
  180.  
  181.     if commentless[2] {
  182.         comment := commentless[2]
  183.         mousegetpos, x, y
  184.         tooltip,%comment%,x-80,y+20
  185.         SetTimer,tt,-2000
  186.         }
  187.  
  188.     if ( GetKeyState("CapsLock", "T") ){
  189.         stringUpper,string,string
  190.     }
  191.  
  192.     Clipboard := trim(string)
  193.    
  194.     WinActivate % "ahk_exe " imageEditor
  195.     send,{CtrlDown}{v}{CtrlUp}
  196.     return
  197. }  
  198.  
  199. lineSplit(str) {
  200.     Loop, % StrLen(str)
  201.     {
  202.         stringleft, first, str, 1
  203.         If (first = "-")
  204.             stringtrimleft, str, str, 1
  205.         else
  206.             return str
  207.     }
  208.     return str
  209. }
  210. return
  211.  
  212. tt:
  213. ToolTip
  214. return
  215.  
  216.  
  217. SetImageEditor:
  218. tryAgainImage:
  219. gui,setI:destroy
  220. gui,setI:Add,text,,Click on your Image Editor
  221. gui,setI:-caption +AlwaysOnTop
  222. gui,setI:show
  223.  
  224. WinWaitNotActive,ahk_exe AutoHotkey.exe
  225. gui,setI:destroy
  226. winget,choiceImage,ProcessName,A
  227. msgbox,4,,is %choiceImage% your prefered Image Editor?
  228. IfMsgBox,Yes
  229. {
  230.     iniwrite,%choiceImage%,%ini%,editors,imageEditor
  231.     goto,SetTextEditorPrep
  232. }
  233. IfMsgBox,No
  234. {
  235.     gosub,tryAgainImage
  236. }
  237.  
  238. SetTextEditorPrep:
  239. gui,setI:new,,Set Text Editor
  240. gui,setI:Margin,5,5
  241. gui,setI: +AlwaysOnTop
  242. gui,setI:add,text,,open your prefered text editor and place the window in an`neasily accessible location.`nThen press OK and proceed to click on the window of your`ntext editor
  243. gui,setI:add,button, w80 x215 gSetTextEditor, Ok
  244. gui,setI:show,w300
  245. return
  246.  
  247.  
  248. SetTextEditor:
  249. tryAgainText:
  250. gui,setI:destroy
  251. gui,setI:Add,text,,Click on your Text Editor
  252. gui,setI:-caption +AlwaysOnTop
  253. gui,setI:show
  254.  
  255. WinWaitNotActive,ahk_exe AutoHotkey.exe
  256. gui,setI:destroy
  257. winget,choiceText,ProcessName,A
  258. msgbox,4,,is %choiceText% your prefered Text Editor?
  259. {
  260.     iniwrite,%choiceText%,%ini%,editors,textEditor
  261.     Msgbox The script will now Reload
  262.     Reload
  263.     msgbox reload failed
  264.     return
  265. }
  266. IfMsgBox,No
  267. {
  268.     ;SoundBeep
  269.     gosub,tryAgainText
  270. }
  271. return
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top