Advertisement
n8abx9

Copy the paragraph of a highlighted word to file

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