Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Function:
- ; Copies lines from a notepad-like text editor to your clipboard and pastes them into a program of your choice.
- ; detailed feature description will be displayed during the setup
- ; 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
- #NoEnv
- SendMode Input
- SetWorkingDir %A_ScriptDir%
- #Persistent
- #singleinstance force
- ;#include debug.ahk
- ;gui,log:show
- ; to avoid calling a nonexistent function when debug.ahk isn't available
- debug(str) {
- }
- ini = ScriptParser.ini
- if not FileExist(ini){
- debug("file " ini " not found")
- iniwrite,dummy,%ini%,editors,imageEditor
- iniwrite,dummy,%ini%,editors,textEditor
- }
- IniRead,image,%ini%,editors,imageEditor
- IniRead,text,%ini%,editors,textEditor
- IniRead,firststartup,%ini%,first,first
- if (firststartup = "ERROR") {
- 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.
- iniwrite,0,%ini%,first,first
- }
- if (image = "dummy" ) or (text = "dummy" ) {
- msgbox ini file has incomplete configuration.`nSetup required.`nPlease press [Ok] and follow the instructions
- gui,setI:new,,Set Image Editor
- gui,setI:Margin,5,5
- gui,setI: +AlwaysOnTop
- 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
- gui,setI:add,button, w80 x215 gSetImageEditor, Ok
- gui,setI:show,w300
- }
- global TextEditor := text
- global ImageEditor := image
- return
- #if winactive("ahk_exe " . ImageEditor) or winactive("ahk_exe " . TextEditor) and WinExist("ahk_exe " . TextEditor) and WinExist("ahk_exe " . ImageEditor)
- F3:: ;;;;;;;;;;;hotkey for this action. for modifier keys use: Ctrl->^, Alt->!, Shift->+. Example: Shift+Q -> +q:: ;;;;;;;;;;;;;;
- ;SoundBeep
- debug("// script parser activated")
- ScriptParser()
- return
- +F3::
- failsafe := 0
- ignore := 0
- debug(prevPage activated)
- prevPage()
- return
- #if
- prevPage() {
- nextline:
- if (failsafe >= 30)
- if (ignore != 1) {
- msgbox,4,,advanced %failsafe% times without finding start of page. Continue?
- ifmsgbox,Yes
- ignore := 1
- ifmsgbox,No
- return
- }
- mousegetpos, x, y
- tooltip,going to top of page,x-80,y+10
- SetTimer,tt,-1000
- Clipboard := ""
- WinActivate % "ahk_exe " textEditor
- sleep 1
- send,{up}{Home}
- sleep 1
- Send,{Home}+{End 4} ; home sets cursor to start of line, +End holds shift and moves cursor to end of line
- sleep 1
- Send,{CtrlDown}{c}{CtrlUp} ; copies the selected line
- sleep 1
- string := Clipboard
- stringright, last, string, 1
- If (last = "-") {
- return
- }
- else {
- goto,nextline
- }
- }
- ScriptParser()
- {
- next:
- failsafe += 1
- if (failsafe >= 15)
- if (ignore != 1) {
- msgbox,4,,advanced %failsafe% times without finding a new line of text. Continue?
- ifmsgbox,Yes
- ignore := 1
- ifmsgbox,No
- return
- }
- Clipboard := ""
- WinActivate % "ahk_exe " textEditor
- ;soundbeep,100
- Send,{Home}+{End 4} ; home sets cursor to start of line, +End holds shift and moves cursor to end of line
- sleep 1
- Send,{CtrlDown}{c}{CtrlUp} ; copies the selected line
- sleep 1
- Send,{Down}{Home} ; go to start of next line
- sleep 1
- if InStr(Clipboard,"#") {
- commentless := StrSplit(Clipboard,"#",,2)
- string := commentless[1]
- }
- else {
- string := Clipboard
- }
- Lsplit := lineSplit(Clipboard)
- if (Lsplit = "") {
- debug("empty string, advancing")
- mousegetpos, x, y
- tooltip,empty,x-80,y+10
- SetTimer,tt,-1000
- goto, next
- }
- else if ( RegExMatch(Clipboard,"\[.*\]$") ) {
- mousegetpos, x, y
- tooltip,%Clipboard%,x-80,y+10
- SetTimer,tt,-2000
- return
- }
- Clipboard := ""
- debug("copied string: " string)
- global stringArray := StrSplit(string," ",,2)
- debug(StringArray[1] " " StringArray[2])
- if InStr(stringArray[1],":") {
- debug("column found " stringArray[1])
- if (stringArray[2]) {
- debug(stringArray[2])
- string := stringArray[2]
- index1 := stringArray[1]
- mousegetpos, x, y
- tooltip,%index1%,x-80,y+10
- SetTimer,tt,-1000
- }
- else {
- debug("index 2 empty")
- goto, next
- }
- }
- ; this one's for "girl a:" / "girl 1:" etc
- else if RegExMatch(stringArray[2],"^.{1}:") {
- debug(stringArray[2])
- subarray := StrSplit(stringArray[2],": ",,2)
- string := subarray[2]
- index1 := stringArray[1] " " subArray[1]
- mousegetpos, x, y
- tooltip,%index1%,x-80,y+10
- SetTimer,tt,-1000
- }
- if commentless[2] {
- comment := commentless[2]
- mousegetpos, x, y
- tooltip,%comment%,x-80,y+20
- SetTimer,tt,-2000
- }
- if ( GetKeyState("CapsLock", "T") ){
- stringUpper,string,string
- }
- Clipboard := trim(string)
- WinActivate % "ahk_exe " imageEditor
- send,{CtrlDown}{v}{CtrlUp}
- return
- }
- lineSplit(str) {
- Loop, % StrLen(str)
- {
- stringleft, first, str, 1
- If (first = "-")
- stringtrimleft, str, str, 1
- else
- return str
- }
- return str
- }
- return
- tt:
- ToolTip
- return
- SetImageEditor:
- tryAgainImage:
- gui,setI:destroy
- gui,setI:Add,text,,Click on your Image Editor
- gui,setI:-caption +AlwaysOnTop
- gui,setI:show
- WinWaitNotActive,ahk_exe AutoHotkey.exe
- gui,setI:destroy
- winget,choiceImage,ProcessName,A
- msgbox,4,,is %choiceImage% your prefered Image Editor?
- IfMsgBox,Yes
- {
- iniwrite,%choiceImage%,%ini%,editors,imageEditor
- goto,SetTextEditorPrep
- }
- IfMsgBox,No
- {
- gosub,tryAgainImage
- }
- SetTextEditorPrep:
- gui,setI:new,,Set Text Editor
- gui,setI:Margin,5,5
- gui,setI: +AlwaysOnTop
- 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
- gui,setI:add,button, w80 x215 gSetTextEditor, Ok
- gui,setI:show,w300
- return
- SetTextEditor:
- tryAgainText:
- gui,setI:destroy
- gui,setI:Add,text,,Click on your Text Editor
- gui,setI:-caption +AlwaysOnTop
- gui,setI:show
- WinWaitNotActive,ahk_exe AutoHotkey.exe
- gui,setI:destroy
- winget,choiceText,ProcessName,A
- msgbox,4,,is %choiceText% your prefered Text Editor?
- {
- iniwrite,%choiceText%,%ini%,editors,textEditor
- Msgbox The script will now Reload
- Reload
- msgbox reload failed
- return
- }
- IfMsgBox,No
- {
- ;SoundBeep
- gosub,tryAgainText
- }
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement