0

I often have to copy/paste a numeric string but sometimes there are dots or spaces in them. I need to write a script that edits my clipboard string:
- It needs to remove all the dots
- It needs to remove all the spaces/EOF's
- It needs to put all the remaining numbers together and put it back in the clipboard

I'm no scripting king, I've found some useful code but I have no idea how to put all that together.

Example:
- The string " 12345.67" is in my clipboard.
- I need a script that changes this to "1234567" and puts it right back in the clipboard.

Lance
  • 11
  • 1
    As far as I know, clipboard interaction from the javascript code is prevented for security reasons. It is limited to user interactions. – Dellirium Jan 14 '19 at 14:06
  • Duplicate: https://stackoverflow.com/questions/42089713/modify-clipboard-content-after-copy-event-javascript-jquery – Danil Gudz Jan 14 '19 at 14:08
  • Possible duplicate of [Modify Clipboard content after copy event: JavaScript, jQuery](https://stackoverflow.com/questions/42089713/modify-clipboard-content-after-copy-event-javascript-jquery) –  Jan 14 '19 at 14:11
  • Do you actually need to put the string back on the clipboard? Would it make sense to reformat the string when it's pasted? – Piskvor left the building Jan 14 '19 at 14:33

1 Answers1

1

It's not possible to access the clipboard using Javascript except in IE.

Therefore, the user will have to initially copy and paste the contents of their clipboards, and then you can use some JS to change the content and copy it back into the clipboard.

Maximillion Bartango
  • 1,533
  • 1
  • 19
  • 34
  • But it is possible to copy the data from the clipboard with e.clipboardData.setData(); right? Do you have any alternative automation to do the task I need to do? – Lance Jan 14 '19 at 17:54
  • Actually, after reading again, that's exactly what I want. I'm not using IE, I'm using an IBM Kobold application called BlueZone. The program allows keybinding javascripts. I already intended to copy the contents myself, can you help me with the part where javascript pulls the data from the clipboard and changes it? – Lance Jan 15 '19 at 08:46
  • You can't pull data from the clipboard, it can only copy to it. You will have to encourage the user to manually paste the contents of their clipboard somewhere on the page. – Maximillion Bartango Jan 15 '19 at 09:35