Macro Toolworks Products Discussion Forums :: General Discussion
Welcome Guest   
 Subject :GET_TEXT_FROM_CLIPBOARD - Clipboard does not contain text.. 25-11-2011 13:42:43 
Worn
Joined: 13-01-2010 09:02:46
Posts: 25
Location
Hi again,

I just wondered that whenever I try the attached example I get the message

"There is NO text in clipboard."

This only happens if clipboard does contain text AND binary information such as pictures
etc. So if you have copied Some information from a website including text, tables and
graphics this won´t work. I´m looking for an easy way to get only the plain text out of
the clipboard and to discard all formats and graphics. Further I would like to eliminate
all TAB charakters in this plain text. (looking for an easy way without writing files
etc.)

Any ideas?

Thanks
Ben

______________________________________________________________

Example:

<#>
<#> Filter formatted text out of clipboard - leave only unformatted text in clipboard
<#>
<cmds>
<var_oper>(vClipboardText,"",GET_TEXT_FROM_CLIPBOARD,"","", "0")
<if_str>("vClipboardText==_vStrEmpty")
<msg>(-100,-100,"There is NO text in clipboard. ","Message",1)
<else>
<clpput>("%vClipboardText%")
<endif>
IP Logged
Last Edited On: 25-11-2011 13:43:39 By Worn for the Reason
 Subject :Re:GET_TEXT_FROM_CLIPBOARD - Clipboard does not contain text.. 25-11-2011 14:46:06 
petr
Joined: 15-10-2009 11:48:52
Posts: 152
Location
Hi Ben,

I just tested the macro in Macro Toolworks version 7.4.8 and it works fine. If I copied some text to clipboard and run macro it executed without showing the error message. If I put a picture to the clipboard (I did "Print Screen") then the macro executed showing the error message. I have got expected behavior in both cases. Do you also use the latest version 7.4.8?

Best regards,
Petr
IP Logged
 Subject :Re:GET_TEXT_FROM_CLIPBOARD - Clipboard does not contain text.. 25-11-2011 18:58:20 
Worn
Joined: 13-01-2010 09:02:46
Posts: 25
Location
Hi Petr,

yes I use the latest version. Please try to copy some text that contains pictures too!
So clipboard contains text and pictures both at the same time. Then the error appears
also. I expected the macro to leave only the text in clipboard.

Thanks for your quick replies.

Ben
IP Logged
 Subject :Re:GET_TEXT_FROM_CLIPBOARD - Clipboard does not contain text.. 30-11-2011 13:01:50 
Worn
Joined: 13-01-2010 09:02:46
Posts: 25
Location
Hi again,

so Ie´v tried some other functions to solve this the easy way but it did not work.

What I need:

Get only text components out of clipboard. That means if there are RTF, Binary etc.
information in clipboard this should be discarded. In a second step I would like to
remove all TAB characters out of the plain text left in clipboard.

__________

I´ve tried to save clipboard informaton to a variable an then save this to file but that
did not work. Also saving clipboard directly to file (clx file) is no solution a the
content of this file contains lot of charcters and meta information sourrounding the
text parts (but maybe it is possible to extract, this would be no easy way). Currently
I´m thinking about pasting the clipboard information to a notepad window, then reselect
all and copy to clipboard again (as notepad deletes all format information and also the
graphics etc.) but I don´t like this idea yet.

Regards
Ben
IP Logged
 Subject :Re:GET_TEXT_FROM_CLIPBOARD - Clipboard does not contain text.. 30-11-2011 15:40:56 
Worn
Joined: 13-01-2010 09:02:46
Posts: 25
Location
Hi again,

tried the idea with notepad and guess what: It works!

Not the best solution yet but ok. It´s a bit quick´n dirty but maybe it´ll help someone
els so i´ll paste the code here. The beginning is copied from the safe notepad start
example.
Code:
<cmds><keys_block> <#> <#> Sample: Start Notepad and type text in it - safe way <#> local variables <varset>("vbTemp_Output=_vStrEmpty","") <varset>("vCounter1=0","") <varset>("vCounter2=0","") <varset>("vLength=_vStrEmpty","") <varset>("vFirstLineFlag=0","") <#> copy the selected text <clp_copyselected>(0,6) <#> exit macro if clipboard is empty <if_clp>("EMPTY","") <msg>(-100,-100,"Empty clipboad","Meldung",1,0,0,1) <exitmacro> <endif> <#> start notepad and activate <execappex>("notepad.exe","","",0,0) <#> Wait until Notepad is loaded <waitfor>("WIN","OPEN","mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",5,0) <#> Make Notepad window active <actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no") <#> Make sure the Notepad window is active <if_win>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ","ACT",0) <wx>(350,1) <#> paste, select all and crop <keys><ctrl>v<ctrl><wx>(150,1)<ctrl>a<ctrl><wx>(150,1)<ctrl>x<ctrl><wx>(250,1)<alt><F4><alt><cmds> <#> set text align left for text out of clipboard <var_oper>(vResultText,"%_vClpText%",TEXT_ALIGN_LEFT,"","","") <#> count number of lines and loop over all lines <var_oper>(vbTemp_NumOfLines,"vResultText",TEXT_GET_NUMOFLINES,"","", "0") <#><msg>(-100,-100,"%vbTemp_NumOfLines%","Meldung",1,0,0,1) <if_str>("vbTemp_NumOfLines<=1") <exitmacro> <endif> <#> beginn of lopp over all lines from clipboard text <begloop>(vbTemp_NumOfLines) <#> get current line (from loop number) <var_oper>(vbTemp_LineText,"vResultText",TEXT_GET_LINE,"_vLoopCounter","", "0") <#> delete all apostrophs <#><var_oper>(vbTemp_LineText,"%vbTemp_LineText%",STR_REPLACE,"'","", "0") <#> remove the character TAB from beginning <#><var_oper>(vbTemp_LineText,"%vbTemp_LineText%",STR_TRIMLEFT," ","", "0") <#><var_oper>(vbTemp_LineText,"%vbTemp_LineText%",STR_TRIMRIGHT," ","", "0") <var_oper>(vbTemp_LineText,"%vbTemp_LineText%",STR_REPLACE," ","", "0") <#> get the length of the line <var_oper>(vLength,"%vbTemp_LineText%",STR_LENGTH,"","", "0") <#> if length is smaller that 1 and counter 2 is 1 then skip loop (removes empty lines from text) <if_str>("(vLength<=1)_AND_(vCounter2==1)") <goto>("SkipLoop") <else> <#> if not then reset counter 2 <varset>("vCounter2=0","") <endif> <#> if line length is smaller than 1 add 1 to counter1 <if_str>("vLength<1") <var_oper>(vCounter1,"%vCounter1%+1",CALC_EXPRESSION,"0","", "0") <endif> <#> if there are more then 2 empty lines after another then skip loop and set flag counter2 ==1 <if_str>("vCounter1==3") <var_oper>(vCounter2,"%vCounter2%+1",CALC_EXPRESSION,"0","", "0") <varset>("vCounter1=0","") <goto>("SkipLoop") <endif> <#><msg>(-100,-100,"%vbTemp_Output%","Meldung",1,0,0,1) <#> check the output string / append all lines <#> IMPORTANT! if both is false than this expression ist true! <if_str>("vbTemp_Output==_vStrEmpty") <if_str>("vFirstLineFlag==0") <varset>("vFirstLineFlag=1","") <varset>("vbTemp_Output=vbTemp_LineText","") <else> <goto>("ElseWay") <endif> <else> <label>("ElseWay") <#><msg>(-100,-100,"Input wäre: %vbTemp_Output%","Meldung",1,0,0,1) <var_oper>(vbTemp_Output,"%vbTemp_Output%",STR_APPEND,"%_vKeyReturn%%vbTemp_LineText%","", "0") <endif> <label>("SkipLoop") <#><msg>(-100,-100,"%vCounter1%","Meldung",1,0,0,1) <endloop> <#> put output text to clipboard <clpput>("%vbTemp_Output%") <endif><keys_unblock>
IP Logged
Last Edited On: 01-12-2011 14:39:23 By Worn for the Reason
Page # 


Powered by ccBoard


Login and share your experience - send messages to forums and add comments to samples, commands and other resources.



Account is free of charge, easy to setup.