3

How to convert clipboard formatted text to plain text with Autohotkey on just a few programs only? Let say on google chrome?

OnClipboardChange:
if (A_EventInfo = "1") {
  Clipboard=%Clipboard%
}
return

This works perfect, but how to limit it to chrome only? If I wrap with #IfWinActive don't do any limitation, just works everywhere.

#IfWinActive ahk_class Chrome_WidgetWin_1
  code goes here
#IfWinActive
Tomas
  • 123
  • 2
  • 14

2 Answers2

1

I tried to create small separate script, and this one works for me as you described (strips off the formatting when I copy something from the Chrome browser):

#SingleInstance
#Persistent

SetTitleMatchMode, 2

OnClipboardChange:
if (A_EventInfo = 1) and (WinActive("Chrome")) {
  Clipboard=%Clipboard%
}
return

You may of course use WinActive("ahk_class Chrome_WidgetWin_1") instead of WinActive("Chrome") as you did in your example, that also works.

stansult
  • 1,323
  • 10
  • 18
  • 1
    If I try to use `WinActive("Chrome_WidgetWin_1")` not working, but works with `WinActive("Chrome")`. What means Chrome? Its not ahk_class name. Also `WinActive ahk_class Chrome_WidgetWin_1` not working. Should I use something else instead of ahk_class name? – Tomas Mar 17 '16 at 09:23
  • WinActive checks the whole window title. When I check Chrome browser’s window title, here’s what I see: `Autohotkey - convert clipboard formatted text to plain text - Stack Overflow - Google Chrome ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe` – stansult Mar 18 '16 at 04:26
  • So it means that you can use actual text title, or ahk_class, or ahk_exe, or all of them, or any part of any of them. Just don’t forget to set TitleMatch to 2 by `SetTitleMatchMode, 2` – stansult Mar 18 '16 at 04:33
  • I think “Chrome_WidgetWin_1” doesn’t work for you because if you are using ahk_class, you should specify it like this: `WinActive("ahk_class Chrome_WidgetWin_1")`. So I was wrong when I wrote it like `WinActive("Chrome_WidgetWin_1")` − this way it probably only looks into the actual text title, and doesn’t check ahk_class. I edited my answer, thanks. – stansult Mar 18 '16 at 04:38
  • I personally don’t like to use classes with numbers (like “Chrome_WidgetWin_1”), because when I see them, I start thinking that there should be “Chrome_WidgetWin_2” somewhere, and so on… :) – stansult Mar 18 '16 at 04:42
1

Complete code to remove formatting from text on chrome and firefox:

#SingleInstance
#Persistent

SetTitleMatchMode, 2

OnClipboardChange:
if (A_EventInfo = 1) and WinActive("ahk_class Chrome_WidgetWin_1") or WinActive("ahk_class MozillaWindowClass") {
 Clipboard=%Clipboard%
}
return
Tomas
  • 123
  • 2
  • 14