Clipboard with content filter - Autohotkey

Asked

Viewed 401 times

2

you have an idea of how to automate the following situation?

I’m using Autohotkey for this.

I will tell you the situation and then I will tell you the hypotheses I considered (part of them only, since I could not finish)

1 - I give Ctrl+c in a content with several lines, I will call them 1,2,3,4,5 and 6 to facilitate logic.

I just want to copy the line 2, 3, 4 and 5 but also with selection of content in the lines, that is, not copy the whole line 2, only the numbers (delete the texts). The same goes for other lines, but with another type of filter.

2 - The script then sends pro Clipboard only the desired content of line 2, 3, 4 and 5 and then inserts in an output file only the desired content of line 2 with another default text. The same happens for the other lines.

Example: Line 2 has "XYZ123". The script copies "123" only and sends the output file "ABC123". The same occurs for other lines.

3 - The script after copying all lines, inserts a new line 7 of my choice that will exist only in the output file.

4 - The script then waits for the next CTRL+C to repeat the process with the next CTRL+C.

PS: The lines are not always in the same order. For example, the content of line 2 is sometimes on line 3. But there is always a keyword in each line that can be used to filter your content.

The next step would be to take Ctrl+c already automatically in the content, but I will stick first to resolve this impasse.

Hypotheses I’ve considered:

1 - To separate each row and paste always in the same order, use variables to assume the value of the row already with unwanted content deleted.

2 - If you can’t automate the order of the lines, it’s okay to use hotkeys to decide which line is which or a system message to ask me that and act on the answer.

clipboard =  ; Começa o script com o clipboard vazio

ClipWait  ; Espera encher o clipboard
FileAppend, %clipboard%`r`n, C:\Users\caio_\Desktop\Teste de programação\Saída.txt ; Joga pro arquivo de saída
MsgBox Control-C copied the following contents to the clipboard:`n`n%clipboard% ; Aparece uma confirmação do que foi copiado (vou tirar quando estiver tudo funcionando)

Reload ; Pra reabrir o script
Sleep 1000 ; 
MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
IfMsgBox, Yes, Edit
return

Edit to better explain the doubt: the problem is that I could not find a way to filter the content of the Clipboard and so I could not integrate other commands to result in my idea. The goal is to find a way to filter the content, which I really couldn’t find. By doing this, I can figure out how to work the rest. I described the whole situation in case someone gives a good idea of how to throw it to an output file in the best way.

  • The idea is quite well described, but what exactly is the doubt? If you can [Dit] post and comment on what you tried, and what problem you found, or what didn’t work, it might be easier to help. The way it is, the question is a bit wide and vague. Maybe it helps: [Tour], [Ask] and [Help].

1 answer

1

Although this topic is more than a year old, it may be that the solution helps other people.

The desired here is a search and replace regex; Regexmatch is the function for this job.

The Ahk uses this type of regex

Example:

Loop {
  Clipboard := ""
  ClipWait
  clip_conteudo := Clipboard

  ; Separa o conteúdo do clipboard em linhas. clip_conteudo passa a ser Array.
  clip_conteudo := StrSplit(clip_conteudo, "`n")

  ; Agora basta tratar o conteúdo de cada linha Pode facilmente se converter em um for
  RegExMatch(clip_conteudo[1], "([^ ]*\d+[^ ]*)", linha_1)
  RegExMatch(clip_conteudo[2], "([^ ]*\d+[^ ]*)", linha_2)
  RegExMatch(clip_conteudo[3], "([^ ]*\d+[^ ]*)", linha_3)
  RegExMatch(clip_conteudo[4], "([^ ]*\d+[^ ]*)", linha_4)
  RegExMatch(clip_conteudo[5], "([^ ]*\d+[^ ]*)", linha_5)
  RegExMatch(clip_conteudo[6], "([^ ]*\d+[^ ]*)", linha_6)

  ; Trata-se dos dados de maneira desejada
  linha_1 := RegExReplace(linha_1, "(\D+)(\d+)", "ABC$2")
  linha_7 := linha_2 + linha_3

  ; Mesma coisa que: clip_conteudo = %linha_1%`n%linha_2%`n [...]
  clip_conteudo =
  (LTrim
    %linha_1%
    %linha_2%
    %linha_3%
    %linha_4%
    %linha_5%
    %linha_6%
    %linha_7%
  )

  FileAppend, %clip_conteudo%`n, Saída.txt 
}

Esc::ExitApp

For the pseudo-text:

Contrary to popular belief, Lorem Ipsum is not simply random text. XYZ123 .
It has roots in a piece of classical Latin literature from 45 BC,
making it over 2000 years old.
Lorem Ipsum comes from sections 1.10.32 and
1.10.33 of "de Finibus Bonorum et Malorum"
Generated 1 paragraph, 44 words, - bytes of Lorem Ipsum 27/03/2019

The pseudo-exit will be:

ABC123
45
2000
1.10.32
1.10.33
1
2045

Browser other questions tagged

You are not signed in. Login or sign up in order to post.