Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'ProcessClipboard v1.0.1, 2024-06-16.
- 'https://www.reddit.com/user/jcunews1
- 'https://pastebin.com/u/jcunews
- 'https://greasyfork.org/en/users/85671-jcunews
- '
- 'Process and modify clipboard text content.
- 'Change code in the "process" function as needed.
- '
- 'Optional command line switches:
- '/C Generate CTRL+C keyboard shortcut to copy selection into clipboard
- ' before processing the retrieved clipboard content.
- '/V Generate CTRL+V keyboard shortcut to paste clipboard content after
- ' processing the retrieved clipboard content.
- '
- 'This script is meant to be run using WSCRIPT.EXE from a program shortcut file
- 'which is configured with a hotkey.
- 'this script use msie to set clipboard content.
- 'for performance reason, msie instance is kept for up to specified duration of
- 'time (in seconds) for use by any next instance of this script.
- timeToKeepMsie = 2 * 60
- 'txt variable contains the clipboard content. change it as needed.
- sub process
- txt = ucase(txt)
- end sub
- set ws = createobject("wscript.shell")
- 'generate CTRL+C keyboard shortcut with /c command line switch
- if wscript.arguments.named.exists("c") then ws.sendkeys "^c"
- 'get clipboard content
- txt = createobject("htmlfile").parentwindow.clipboarddata.getdata("text")
- if txt = null then
- msgbox "Clipboard doesn't contain any usable text data.", 16, _
- "ProcessClipboard"
- wscript.quit
- end if
- 'process text from clipboard
- process
- 'get script-created msie instance
- set ie= nothing
- set sa = createobject("shell.application")
- for each o in sa.windows
- if o.getproperty("createdBy") = "thisScript" then
- set ie = o
- exit for
- end if
- next
- 'if not yet exist, create new msie instance
- if ie is nothing then
- set ie = createobject("internetexplorer.application")
- ie.putproperty "createdBy", "thisScript"
- ie.navigate "about:blank" 'meh. msie doesn't support Data URI
- t = timer
- do while ie.readystate <> 4
- if (timer - t) >= 3 then
- ie.quit
- msgbox _
- "Timeout waiting for Internet Explorer to complete a blank page.", 16 _
- "ProcessClipboard"
- wscript.quit
- end if
- wscript.sleep 20
- loop
- set doc = ie.document
- set ta = doc.createelement("textarea")
- ie.putproperty "ta", doc.body.appendchild(ta)
- else
- set ta = ie.getproperty("ta")
- end if
- 'set clipboard content
- ta.value = txt
- ta.select()
- ie.execwb 12, 2 'OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER
- 'generate CTRL+V keyboard shortcut with /v command line switch
- if wscript.arguments.named.exists("v") then ws.sendkeys "^v"
- 'set/update time of last used msie instance. recheck for up to timeToKeepMsie.
- 'if changed, hand over msie instance to other script then end script.
- 'otherwise, when timed out, close msie instance then end script.
- secondunit = 1 / (24 * 60 * 60)
- timelastused = now
- ie.putproperty "timeLastUsed", timelastused
- do while true
- if (ie.getproperty("timeLastUsed") = timelastused) and _
- ((now - timelastused) < (timeToKeepMsie * secondunit)) then
- wscript.sleep 200
- else
- ie.quit
- wsh.quit
- end if
- loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement