Convert Clipboard Text To Plain Text

#1
I communicate with a person via Yahoo Mail. All correspondence is in English.

On occasion, I copy text from an email, and paste it into an app that allows me to send a text message via SMS to a cell phone.

For whatever reason, when the person receives the SMS message on their cell phone, the text is in Chinese characters. So, I tried sending the same text to my cell phone, and it also arrived in Chinese characters.

The problem is unique only to this contact in my Yahoo Mail.

With the copied text on the clipboard, I used CLIPFMT.BTM from http://jpsoft.com/forums/threads/detect-clipboard-format.5227/#post-30210 and found the following;

Code:
There are 11 clipboard formats.
49161 - DATAOBJECT
49590 - UNKNOWN
49403 - UNKNOWN
49808 - UNKNOWN
49810 - UNKNOWN
 13 - CF_UNICODETEXT
 1 - CF_TEXT
49811 - UNKNOWN
49171 - Ole Private Data
 16 - CF_LOCALE
7 - CF_OEMTEXT
My solution was to create the CLP2TXT.BTM...

Code:
@setlocal
@echo off
set thefile=%@unique[]
type clip: > %thefile
type %thefile > clip:
if exist %thefile del /w %thefile > nul
Endlocal
...which, when run, converts the text on the clipboard to plain text. After running CLP2TXT.BTM, CLIPFMT.BTM now returns...

Code:
 13 - CF_UNICODETEXT
 16 - CF_LOCALE
 1 - CF_TEXT
7 - CF_OEMTEXT
...and the text no longer appears as Chinese characters when I send it via SMS to a cell phone.

Joe
 
#2
Neat! I have a comment though. If one uses the NoClobber=Yes option, %thefile already exists, but is empty. My simple solution is to append the redirected text thus:
type clip: >> %thefile
BTW, I presume the if exist test before DEL is intended to eliminate the warning message from DEL if its target is already absent. The /NE option of DEL (available since 4NT 7) does that without an extra test. This option is available in most commands which manipulate the file system to avoid error reports when the file system is in the desired state without the command doing anything.
 
#4
You might try PureText by Steve Miller which you can find at http://www.stevemiller.net/puretext/ .
I used to use that, as it allowed me to, if I remember correctly, do a puretext /c from the command line, to do basically the same thing that I am doing with the batch file. As I did not use it all the time, though, I figured that the memory it was using would be better used by another program, so I no longer use it.

After reading Steve's message, I re-wrote CLP2TXT.BTM;

Code:
@setlocal
@echo off
set thefile=%@unique[]
iff exist %thefile then
  type clip: > %thefile
  type %thefile > clip:
  del /w %thefile > nul
  echo Clipboard contents should now be plain text.
else
  echo Error creating temporary file.
  echo Clipboard contents not modified.
endiff
endlocal
Laziness on my part, I suppose, for not originally including the logic to check for the existence of the temporary file first, before placing the contents of the clipboard on it.

Joe
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#5
Another option that many apps have is when you go to paste, instead of the default Ctrl+V paste, select the "Paste As..." option or "Paste as plain text" option. I find that allows me to skip the manual conversion step.

Also, TPIPE can handle this without the need for temporary files.

Code:
type clip: |! tpipe /simple=3u /output=clip:
I tried used the /clipboard switch but got an error. According to the TPIPE docs, I'd have expected this to work:
Code:
tpipe /clipboard /simple=3u
But it returns an error (I'll report that in a separate thread).
 
#6
Another option that many apps have is when you go to paste, instead of the default Ctrl+V paste, select the "Paste As..." option or "Paste as plain text" option. I find that allows me to skip the manual conversion step.
I thought of that also, but the app I am using to paste into the SMS Message does not have the "Paste As..." option.

Also, TPIPE can handle this without the need for temporary files.
Code:
type clip: |! tpipe /simple=3u /output=clip:
It continues to amaze me how versatile the TPIPE command is. Someone needs to write a book (or help file) with thorough examples. This has *greatly* reduced the size of CLP2TXT.BTM. Many Thanks!

I tried used the /clipboard switch but got an error. According to the TPIPE docs, I'd have expected this to work:
Code:
tpipe /clipboard /simple=3u
But it returns an error (I'll report that in a separate thread).
I am using;

Code:
TCC  15.01.57  Windows Vista [Version 6.0.6002]
TCC Build 57  Windows Vista Build 6002  Service Pack 2
but the help for TPIPE does not show the /clipboard option. What version of TCC are you using?

Joe
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#7
Sorry Joe, I didn't realize that switch wasn't in V15.
This is simpler without the need for the pipe:
Code:
tpipe /input=clip: /output=clip: /simple=3u