Advertisement
jcunews

ProcessClipboard.vbs

Jun 16th, 2024
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'ProcessClipboard v1.0.1, 2024-06-16.
  2. 'https://www.reddit.com/user/jcunews1
  3. 'https://pastebin.com/u/jcunews
  4. 'https://greasyfork.org/en/users/85671-jcunews
  5. '
  6. 'Process and modify clipboard text content.
  7. 'Change code in the "process" function as needed.
  8. '
  9. 'Optional command line switches:
  10. '/C  Generate CTRL+C keyboard shortcut to copy selection into clipboard
  11. '    before processing the retrieved clipboard content.
  12. '/V  Generate CTRL+V keyboard shortcut to paste clipboard content after
  13. '    processing the retrieved clipboard content.
  14. '
  15. 'This script is meant to be run using WSCRIPT.EXE from a program shortcut file
  16. 'which is configured with a hotkey.
  17.  
  18. 'this script use msie to set clipboard content.
  19. 'for performance reason, msie instance is kept for up to specified duration of
  20. 'time (in seconds) for use by any next instance of this script.
  21. timeToKeepMsie = 2 * 60
  22.  
  23. 'txt variable contains the clipboard content. change it as needed.
  24. sub process
  25.   txt = ucase(txt)
  26. end sub
  27.  
  28. set ws = createobject("wscript.shell")
  29.  
  30. 'generate CTRL+C keyboard shortcut with /c command line switch
  31. if wscript.arguments.named.exists("c") then ws.sendkeys "^c"
  32.  
  33. 'get clipboard content
  34. txt = createobject("htmlfile").parentwindow.clipboarddata.getdata("text")
  35. if txt = null then
  36.   msgbox "Clipboard doesn't contain any usable text data.", 16, _
  37.     "ProcessClipboard"
  38.   wscript.quit
  39. end if
  40.  
  41. 'process text from clipboard
  42. process
  43.  
  44. 'get script-created msie instance
  45. set ie= nothing
  46. set sa = createobject("shell.application")
  47. for each o in sa.windows
  48.   if o.getproperty("createdBy") = "thisScript" then
  49.     set ie = o
  50.     exit for
  51.   end if
  52. next
  53.  
  54. 'if not yet exist, create new msie instance
  55. if ie is nothing then
  56.   set ie = createobject("internetexplorer.application")
  57.   ie.putproperty "createdBy", "thisScript"
  58.   ie.navigate "about:blank" 'meh. msie doesn't support Data URI
  59.  t = timer
  60.   do while ie.readystate <> 4
  61.     if (timer - t) >= 3 then
  62.       ie.quit
  63.       msgbox _
  64.         "Timeout waiting for Internet Explorer to complete a blank page.", 16 _
  65.         "ProcessClipboard"
  66.       wscript.quit
  67.     end if
  68.     wscript.sleep 20
  69.   loop
  70.   set doc = ie.document
  71.   set ta = doc.createelement("textarea")
  72.   ie.putproperty "ta", doc.body.appendchild(ta)
  73. else
  74.   set ta = ie.getproperty("ta")
  75. end if
  76.  
  77. 'set clipboard content
  78. ta.value = txt
  79. ta.select()
  80. ie.execwb 12, 2 'OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER
  81.  
  82. 'generate CTRL+V keyboard shortcut with /v command line switch
  83. if wscript.arguments.named.exists("v") then ws.sendkeys "^v"
  84.  
  85. 'set/update time of last used msie instance. recheck for up to timeToKeepMsie.
  86. 'if changed, hand over msie instance to other script then end script.
  87. 'otherwise, when timed out, close msie instance then end script.
  88. secondunit = 1 / (24 * 60 * 60)
  89. timelastused = now
  90. ie.putproperty "timeLastUsed", timelastused
  91. do while true
  92.   if (ie.getproperty("timeLastUsed") = timelastused) and _
  93.     ((now - timelastused) < (timeToKeepMsie * secondunit)) then
  94.     wscript.sleep 200
  95.   else
  96.     ie.quit
  97.     wsh.quit
  98.   end if
  99. loop
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement