danrim

ahk menu store more clipboards tool

Jan 17th, 2022 (edited)
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;https://www.autohotkey.com/boards/viewtopic.php?f=76&t=98723
  2. ; dont forget to create .ini file
  3.  
  4. SendMode Input                                                  ; Recommended for new scripts due to its superior speed and reliability.
  5. SetWorkingDir %A_ScriptDir%                                     ; Ensures a consistent starting directory.
  6. #SingleInstance, Force
  7. SetKeyDelay, -1  
  8.  
  9. clip := [], maxClips := 2, maxTitleLen := 20    
  10. Loop, %maxClips% {
  11.  Menu, %A_Index%, Add, Copy, Copy
  12.  Menu, clips, Add, CLIP%A_Index% =, :%A_Index% ; Create a main menu item
  13. }
  14. Menu, clips, Add
  15. Menu, clips, Add, Clear All, ClearAll
  16.  
  17. !LButton Up::
  18. KeyWait, Alt
  19. Menu, clips, Show
  20. Return
  21.  
  22. Copy:
  23. myinipath = C:\Users\Name\Desktop\test1.ini ; file content [Section]
  24. Clipboard =
  25. Send ^c                                                                  
  26. ClipWait, 0
  27. If !ErrorLevel {
  28.  clip[A_ThisMenu] := Clipboard    ; Store the full clip
  29.  Menu, clips, Rename, %A_ThisMenu%&, % SubStr(Clipboard, 1, maxTitleLen) ; Change item name to short title
  30.  Menu, %A_ThisMenu%, Add, Paste
  31.  Menu, %A_ThisMenu%, Add, Clear
  32. } Else MsgBox, 48, Error, An error occurred while waiting for the clipboard.
  33.  
  34. IniWrite,  % SubStr(Clipboard, 1, maxTitleLen), %myinipath%, Section, %A_ThisMenu%
  35. Return
  36.  
  37. ; use ini variable in template
  38. ;~ myinipath = C:\Users\Name\Desktop\test1.ini
  39. ;~ IniRead, OutputVar, %myinipath%, Section, 1
  40. ;~ MsgBox, %OutputVar%
  41.  
  42.  
  43. Paste:
  44. content := clip[A_ThisMenu]
  45. Clipboard := content
  46. send, ^v
  47. ;SendInput % "{Text}" clip[A_ThisMenu]  ; Paste clip by menu item number
  48.  
  49. clip.RemoveAt(A_ThisMenu)
  50. Menu, clips, Rename, %A_ThisMenu%&, CLIP%A_ThisMenu% =
  51. Menu, %A_ThisMenu%, Delete, Paste
  52. Menu, %A_ThisMenu%, Delete, Clear
  53.  
  54. emptyVar =
  55. IniWrite, %emptyVar%, %myinipath%, Section, %A_ThisMenu%
  56. Return
  57.  
  58.  
  59. Clear:
  60. clip.RemoveAt(A_ThisMenu)
  61. Menu, clips, Rename, %A_ThisMenu%&, CLIP%A_ThisMenu% =
  62. Menu, %A_ThisMenu%, Delete, Paste
  63. Menu, %A_ThisMenu%, Delete, Clear
  64.  
  65. emptyVar =
  66. IniWrite, %emptyVar%, %myinipath%, Section, %A_ThisMenu%
  67. Return
  68.  
  69.  
  70. ClearAll:
  71. myinipath = C:\Users\Name\Desktop\test1.ini
  72. emptyVar =
  73. loop, 3 {
  74.  x++
  75. IniWrite, %emptyVar%, %myinipath%, Section, %x%
  76. }
  77. Reload
  78. return
  79.  
Add Comment
Please, Sign In to add comment