MsgBoxCopyText

Post your working scripts, libraries and tools.
william_ahk
Posts: 504
Joined: 03 Dec 2018, 20:02

MsgBoxCopyText

23 Feb 2024, 07:40

Copies the message box text content without the title and buttons when using Ctrl+C.

Code: Select all

; Usage
MsgBoxCopyText()

; Function
MsgBoxCopyText(Enable:=True) => (HotIfWinActive("ahk_class #32770"), Hotkey("~^c up", (*) => RegExMatch(A_Clipboard, ("s)\R-{27}\R(.*?)\R-{27}\R|\R\R\[.*?\]\R(.*?)\R\R(\[.*?\]\R(.*?)\R\R)?"), &Match) && A_Clipboard := Match[1] != "" ? Match[1] : Match[2] (Match[4] != "" ? "`n" Match[4] : ""), Enable ? "On" : "Off"))
Last edited by william_ahk on 29 Feb 2024, 12:04, edited 2 times in total.
User avatar
kunkel321
Posts: 1170
Joined: 30 Nov 2015, 21:19

Re: MsgBoxCopyText

23 Feb 2024, 12:32

Very nice!
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 962
Joined: 02 Jul 2017, 23:47

Re: MsgBoxCopyText

24 Feb 2024, 08:22

Thanks for this useful function.

Correct me if I am wrong, but I think the regex can be reduced by more than 80% using RegExReplace

Code: Select all

MsgBoxCopyText(Enable:=True) => (HotIfWinActive("ahk_class #32770"), Hotkey("~^c up", (*) => A_Clipboard:=RegExReplace(A_Clipboard,"(\R?-{27}\R?)[^\v]+\R(?1)"), Enable?"On":"Off"))
william_ahk
Posts: 504
Joined: 03 Dec 2018, 20:02

Re: MsgBoxCopyText

24 Feb 2024, 09:20

@andymbody Thanks for contributing! I'm also matching for newer message boxes with the format like below. Maybe you can design a more optimized regex including this format? We will need the value in the second section and optionally the third's if it exists.
[Window Title]
Network Error

[Main Instruction]
Windows cannot access \\LTSC

[Content]
Check the spelling of the name. Otherwise, there might be a problem with your network. To try to identify and resolve network problems, click Diagnose.

[V] See details [Diagnose] [Cancel]

[Expanded Information]
Error code: 0x80070043
The network name cannot be found.
User avatar
andymbody
Posts: 962
Joined: 02 Jul 2017, 23:47

Re: MsgBoxCopyText

24 Feb 2024, 10:42

william_ahk wrote:
24 Feb 2024, 09:20
I'm also matching for newer message boxes with the format like below. Maybe you can design a more optimized regex including this format?
Ah... I see the OR now...
Last edited by andymbody on 24 Feb 2024, 12:33, edited 4 times in total.
william_ahk
Posts: 504
Joined: 03 Dec 2018, 20:02

Re: MsgBoxCopyText

24 Feb 2024, 11:42

andymbody wrote:
24 Feb 2024, 10:42
Maybe changing the match variable to m, and changing \R\R to \R+ just to reduce the number of chars
Ah well, I want to keep the style in full words and the match to be exact. But I did realise from your regex that dotall and `a are not needed so I'll remove that.

Edit: Sorry, dotall is still needed for multiline text content.
User avatar
NPerovic
Posts: 40
Joined: 31 Dec 2022, 01:25
Contact:

Re: MsgBoxCopyText

16 Mar 2024, 14:37

An easy way to do the same thing:

Code: Select all

#Requires AutoHotkey v2
MsgBoxCopyText(Enable := true) {
      HotIfWinActive("ahk_class #32770")
      Hotkey("^c", (*) => A_Clipboard := ControlGetText("Static1"), Enable ? "On" : "Off")
}
✨ Dark Theme for Everything
✨ Other Scripts


Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 43 guests