Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Paste plain text (and copy/cut)


  • Please log in to reply
21 replies to this topic
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
The functionality of this simple script is there in a few clipboard management scripts already posted (and in a few freeware utilities, like PureText), but if you don't need other fancy features, this one is short and fast. (The simple method Chris described here often fails.)
^#v::                            ; Text–only paste from ClipBoard
   Clip0 = %ClipBoardAll%
   ClipBoard = %ClipBoard%       ; Convert to text
   Send ^v                       ; For best compatibility: SendPlay
   Sleep 50                      ; Don't change clipboard while it is pasted! (Sleep > 0)
   ClipBoard = %Clip0%           ; Restore original ClipBoard
   VarSetCapacity(Clip0, 0)      ; Free memory
Return
Ctrl-Win-V pastes the text content of the clipboard, leaving it unchanged, so Ctrl-V would still paste formatted text with pictures, if it was in the Clipboard. It is very useful if you paste text from websites into MS Word or Lotus Notes, where they look weird with unusual indentation, font, color, etc. Sleep 50 was necessary in my PC, because setting up the clipboard happens in the background, parallel to the script. If it was not finished when Ctrl-V is sent, the old content was used. Experiment with other values. Sleep 250 should be enough even for the slowest PC's.

If you know, you only need the text content of the selection, but many times, you could save time and memory if the clipboard is converted to text:
^#x::
^#c::                            ; Text-only cut/copy to ClipBoard
   Clip0 = %ClipBoardAll%
   ClipBoard =
   StringRight x,A_ThisHotKey,1  ; C or X
   Send ^%x%                     ; For best compatibility: SendPlay
   ClipWait 2                    ; Wait for text, up to 2s
   If ErrorLevel
      ClipBoard = %Clip0%        ; Restore original ClipBoard
   Else
      ClipBoard = %ClipBoard%    ; Convert to text
   VarSetCapacity(Clip0, 0)      ; Free memory 
Return
Ctrl-Win-C/X copies/cuts the selection to the clipboard and converts it to text.

keybored
  • Members
  • 351 posts
  • Last active: Apr 26 2013 09:08 AM
  • Joined: 18 Jun 2006
This is going to be great. Similar to Skrommels PlainPaste, but the code is easier for me to understand and will fit nicely in my ini file. I'm going to be using this starting tonight.

jak
  • Members
  • 159 posts
  • Last active: Dec 16 2010 11:26 PM
  • Joined: 28 Feb 2006
very nice, useful, and elegant. simple too. I'm using it already. perfect.
By the way what I was looking for was the converter to plain text on the 'copy/cut' keys (rather than on the paste keys). Most such converters do it on the paste key. So your second solution was especially perfect for me.
I needed it that way because of a particular program I use where I have to use a menu command to paste, so it had to be converted on the front end...

atnbueno
  • Members
  • 66 posts
  • Last active: Today, 06:36 AM
  • Joined: 24 Mar 2007
Excellent!

Already in my AutoHotkey.ahk :D

AHKPNH
  • Members
  • 37 posts
  • Last active: Jan 30 2014 11:01 PM
  • Joined: 17 Feb 2006
Very good!!! :p

jak
  • Members
  • 159 posts
  • Last active: Dec 16 2010 11:26 PM
  • Joined: 28 Feb 2006
hi - i've been using lazlo's plain-text-copy script for a while, and its been great. Recently I tried to map the hotkey to the mouse, and I ran into trouble. Wondering whats going on.

The script i'm using is this:

lwin & c::                            ; Text-only cut/copy to ClipBoard
   Clip0 = %ClipBoardAll%
   ClipBoard =
   StringRight x,A_ThisHotKey,1  ; C or X
   Send ^%x%                     ; For best compatibility: SendPlay
   ClipWait 2                    ; Wait for text, up to 2s
   If ErrorLevel
      ClipBoard = %Clip0%        ; Restore original ClipBoard
   Else
      ClipBoard = %ClipBoard%    ; Convert to text
   VarSetCapacity(Clip0, 0)      ; Free memory
Return

all i did was change the hotkey to:

lwin & lbutton::

When I open notepad and try to copy some text using lwin & lbutton, windows tries to close notepad (I get the "would you like to save your work?" prompt).

any ideas why i'm not able to map this to a mouse button? I've also tried variations like "lctrl & rbutton". It only seems happy if the hotkey is limited to the keyboard, not the mouse.

thanks!

(I should add that a line like "lwin & rbutton::send ^v" works fine for pasting, even when mapped to the mouse like that).

Lexikos
  • Administrators
  • 9394 posts
  • Last active:
  • Joined: 17 Oct 2006
Change
StringRight x,A_ThisHotKey,1  ; C or X

   Send ^%x%                     ; For best compatibility: SendPlay
to
Send ^c
otherwise it sends Ctrl+N. :lol:

jak
  • Members
  • 159 posts
  • Last active: Dec 16 2010 11:26 PM
  • Joined: 28 Feb 2006
THanks! works perfectly.

why did it send control-N? because "lbutton" ends with an "N"?

Lexikos
  • Administrators
  • 9394 posts
  • Last active:
  • Joined: 17 Oct 2006
Yes.

sashabe
  • Members
  • 24 posts
  • Last active: Aug 05 2013 11:34 AM
  • Joined: 09 Oct 2006
Is it possible to modify this script so that he'd work with Unicode characters? Now, for example, if cyrillic characters are copied, trash letters like "ââèäó ñïåöèôèê" are pasted.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
If you want to remove formatting from Unicode text use this:
^#v::                            ; Text–only paste from ClipBoard

   Clip0 = %ClipBoardAll%

   Transform UC, Unicode         ; Save Unicode text

   Transform Clipboard, Unicode, %UC%

   Send ^v                       ; For best compatibility: SendPlay

   Sleep 50                      ; Don't change clipboard while it is pasted! (Sleep > 0)

   ClipBoard = %Clip0%           ; Restore original ClipBoard

   VarSetCapacity(Clip0, 0)      ; Free memory

Return
It does not work if the Clipboard contains pictures (too).

instantrunoff
  • Members
  • 115 posts
  • Last active: Oct 10 2011 07:19 PM
  • Joined: 13 Jan 2008
I have a modified version to remove white space and new line marks and that avoids "pasting" because that can trigger unnecessary paste options in Microsoft Office:

$>!v:: ; paste without formatting
  gosub getplain
  Send {Raw}%clipboardt%
  clipboardt = 
  return
  
  getplain:
  StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
  clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
  StringLeft, 1st, clipboardt, 1
  IfInString, 1st, %A_Space%
  StringTrimLeft, clipboardt, clipboardt, 1
  StringRIght, last, clipboardt, 1
  IfInString, last, %A_Space%
  StringTrimRight, clipboardt, clipboardt, 1
  return

Updates May 16, 2008

sashabe
  • Members
  • 24 posts
  • Last active: Aug 05 2013 11:34 AM
  • Joined: 09 Oct 2006

I have a modified version to remove white space and new line marks and that avoids "pasting" because that can trigger unnecessary paste options in Microsoft Office:

>!v:: ; paste without formatting
	  plainpaste:
	  StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
	  clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
	  StringLeft, 1st, clipboardt, 1
	  IfInString, 1st, %A_Space%
	  StringTrimLeft, clipboardt, clipboardt, 1
	  Send %clipboardt%
	  clipboardt = 
	  return


Thanks! It finally works with MS Office, but rather than paste instantly, it "types" the clipboard, and therefore is not for large text fragments.

instantrunoff
  • Members
  • 115 posts
  • Last active: Oct 10 2011 07:19 PM
  • Joined: 13 Jan 2008

I have a modified version to remove white space and new line marks and that avoids "pasting" because that can trigger unnecessary paste options in Microsoft Office:

>!v:: ; paste without formatting
	  plainpaste:
	  StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
	  clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
	  StringLeft, 1st, clipboardt, 1
	  IfInString, 1st, %A_Space%
	  StringTrimLeft, clipboardt, clipboardt, 1
	  Send %clipboardt%
	  clipboardt = 
	  return


Thanks! It finally works with MS Office, but rather than paste instantly, it "types" the clipboard, and therefore is not for large text fragments.


Yeah, I had it "type" the clipboard rather than paste, because it annoyed me to have paste options or automatic formatting applied when pasting. However, you can use SendPlay for something paste-like.

instantrunoff
  • Members
  • 115 posts
  • Last active: Oct 10 2011 07:19 PM
  • Joined: 13 Jan 2008
PS I updated the script to prevent issues sending text with characters that get escaped.