Trim and clear formattin.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Trim and clear formattin.

21 Oct 2021, 07:32

I tried all variants that I found (I think older forum) but none of them works stable.

I need to be able to auto trim begining and ending empty spaces from copied text to clipboard.

Also clear format from copied that like html tags.
Last edited by ozgurerdogan on 21 Oct 2021, 09:07, edited 2 times in total.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: some title

21 Oct 2021, 08:49

Code: Select all

#Persistent
OnClipboardChange("clipChanged")

clipChanged(Type) {
 OnClipboardChange("clipChanged", False)
 text := Clipboard, Clipboard := "", Clipboard := Trim(RegExReplace(text, "<.+?>"))
 ClipWait, 0
 If ErrorLevel
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 OnClipboardChange("clipChanged")
}
I suggest that the subject of your forum post be a short description of the topic or problem.
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: some title

21 Oct 2021, 09:07

Ok hero. Can you please also make one for clear formatting. For example, when I copy text from a web page and paste it to Thunderbird as mail context, I need it to be clear text.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

21 Oct 2021, 09:12

The following command will convert formatted text to plain text.

Code: Select all

Clipboard := Clipboard
Explained: Clipboard
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

22 Oct 2021, 03:48

Hello again,
I noted today that I can not copy and paste files in windows. Also when I take a screen shot, I can not copy it to clipboard. Anyway to fix this.?
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

22 Oct 2021, 05:56

Code: Select all

#Persistent
OnClipboardChange("clipChanged")

clipChanged(type) {
 If WinActive("ahk_class CabinetWClass") || FileExist(plain := Clipboard) || type != TEXT := True
  Return
 OnClipboardChange("clipChanged", False)
 Clipboard := "", Clipboard := Trim(RegExReplace(plain, "<.*?>"))
 ClipWait, 0
 If ErrorLevel
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 OnClipboardChange("clipChanged")
}
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

22 Oct 2021, 06:22

Thank you bro. You helped a lot.
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

15 Dec 2021, 02:11

Hello again,
I noticed sometimes I am getting popup message sayin "error happened when copying text to clipboard"
This happens when I copy raw html tags like: <br> <a> etc.

Is there a way to allow those tags to be copied. I am a web master so I need to use these copying a lot. :)
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

15 Dec 2021, 05:34

You stated that you wanted the script to remove HTML tags. In your case, the result is then null.
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

15 Dec 2021, 05:37

Yes you are right. But I should not touch clipboard if it is only containg tags. Not possible?
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

15 Dec 2021, 05:53

Code: Select all

#Persistent
OnClipboardChange("clipChanged")

clipChanged(type) {
 If WinActive("ahk_class CabinetWClass") || FileExist(plain := Clipboard) || type != TEXT := True
  Return
 If ("" = text := Trim(RegExReplace(plain, "<.*?>")))
  Return
 OnClipboardChange("clipChanged", False), Clipboard := "", Clipboard := text
 ClipWait, 0
 If ErrorLevel
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 OnClipboardChange("clipChanged")
}
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

15 Dec 2021, 06:15

One more thing, sometimes when I paste I see long spaces at end not sure if it is tab or only spaces. Is the code not trimming them or they are something different maybe related to app currently being pasted.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

15 Dec 2021, 06:18

What is your example?
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

15 Dec 2021, 06:22

You can see screenshot:

https://yadi.sk/d/fH_obW9KJcivGg

It is an app has windows with inputs. But if I paste string to notepad then there is no space at end. Only on this app.

Also if I recopy non-spaced text to app again then there is no empty space.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

15 Dec 2021, 06:33

When your script is not running, you can view the invisible characters by pasting the string at the following Web page.

https://www.soscisurvey.de/tools/view-chars.php
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

15 Dec 2021, 06:37

Cool. And I got:

⟶​ CR LF

But this is not a big deal. Script is mostly helpful.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

15 Dec 2021, 06:44

You can trim those, too.

Code: Select all

#Persistent
OnClipboardChange("clipChanged")

clipChanged(type) {
 If WinActive("ahk_class CabinetWClass") || FileExist(plain := Clipboard) || type != TEXT := True
  Return
 If ("" = text := Trim(RegExReplace(plain, "<.*?>"), " `t`r`n"))
  Return
 OnClipboardChange("clipChanged", False), Clipboard := "", Clipboard := text
 ClipWait, 0
 If ErrorLevel
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 OnClipboardChange("clipChanged")
}
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Trim and clear formattin.

15 Dec 2021, 06:47

Thanks that worked too. I though those were also being trimmed.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Trim and clear formattin.

15 Dec 2021, 07:03

The default trim characters for Trim are Space and Tab.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer and 263 guests