Advertisement
Guest User

Copy the context of a highlighted word and save it to a file

a guest
Oct 6th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; TODO: ADAPT FILEPATH BELOW
  2.  
  3. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  4. ; #Warn  ; Enable warnings to assist with detecting common errors.
  5. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  6. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  7.  
  8.  
  9. ^3::
  10. tmp := clipboard
  11. clipboard := ""
  12. Send, ^c
  13. ClipWait, 2
  14. word := RegExReplace(RegExReplace(clipboard, "\r?\n"," "), "(^\s+|\s+$)")
  15. clipboard := ""
  16. bLength := StrLen(clipboard)
  17. rRegex := "[\.!?]"
  18. rReplaceRegex := "(.+[\.!?]+)[^\.!?]*"
  19. lRegex := "[:\.!?]"
  20. lReplaceRegex := ".*[:\.!?]\s*(.+)"
  21. Send, +{End}
  22. Loop
  23. {
  24.     Send, ^c
  25.     ClipWait, 2
  26.     aLength := StrLen(clipboard)
  27.     if ( RegExMatch( clipboard, rRegex ) or bLength == aLength )
  28.         break
  29.     else {
  30.         Send, +{Right}
  31.         clipboard := ""
  32.         bLength := aLength
  33.         continue
  34.     }
  35. }
  36. rContext := RegExReplace(clipboard, rReplaceRegex, "$1" )
  37. clipboard := ""
  38. Sleep, 200
  39. bLength := StrLen(clipboard)
  40. Send, +{Up}
  41. Loop
  42. {
  43.     Send, ^c
  44.     ClipWait, 2
  45.     if ( RegExMatch( clipboard, lRegex ) or bLength == aLength )
  46.         break
  47.     else {
  48.         Send, +{Up}
  49.         clipboard := ""
  50.         bLength := aLength
  51.         continue
  52.     }
  53. }
  54. context := RegExReplace(clipboard, lReplaceRegex, "$1" ) rContext
  55. context := RegExReplace(RegExReplace( context, "\r?\n"," "), "(^\s+|\s+$)")
  56. clipboard := ""
  57. Sleep, 200
  58. IfWinActive ahk_exe firefox.exe
  59. Send, ^l
  60. Sleep, 100
  61. Send, ^c
  62. ClipWait, 2
  63. link := RegExReplace(RegExReplace(clipboard, "\r?\n"," "), "(^\s+|\s+$)")
  64. clipboard := tmp ; restores original clipboard
  65. Sleep, 100
  66. ClipWait
  67. Sleep, 100
  68. ClipWait
  69. FileAppend, %word%;%context%;%link%;`n, C:\Users\TODO\Documents\Anki.csv
  70. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement