Open a .txt file when an 'if' condition is met, then paste clipboard to search file for word, indicate if word found
Posted: 30 Jan 2023, 21:02
How to make a .txt to open automatically when an 'if' condition is met, and then to let me paste my clipboard into a search bar created by the script, to see if the txt file contains that 1 word from my clipboard. It would be a different word every time this script runs. If the word is found, then execute a msgbox saying the word has been found, if not, then return I guess. The ctrl+f search function in notepad is quite flimsy and doesn't do a good job.
I've tried the scripts from these threads but they don't seem to do what I'm trying to do
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=576
https://www.autohotkey.com/boards/viewtopic.php?t=29213
I copied and tried the one below too but I don't really understand how to make it work properly. It looks the closest to my purpose but the word to search for would be defined at the moment by pasting it from my clipboard. I am on AHK V1.1...
I've tried the scripts from these threads but they don't seem to do what I'm trying to do
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=576
https://www.autohotkey.com/boards/viewtopic.php?t=29213
I copied and tried the one below too but I don't really understand how to make it work properly. It looks the closest to my purpose but the word to search for would be defined at the moment by pasting it from my clipboard. I am on AHK V1.1...
Code: Select all
If !FileExist(file := A_ScriptDir "\testFile.txt") { ; I made sure the .txt file is in same folder as the script
MsgBox, 48, Error, File not found. Aborting.`n`n%file%
Return
} Else FileRead, ttext, %file%
If !WinExist(wTitle := "ahk_exe notepad.exe") {
Run, notepad.exe
WinWaitActive, %wTitle%,, 5
If ErrorLevel {
MsgBox, 48, Error, An error occurred while waiting for the window. Aborting.
Return
}
} Else WinActivate
Send % find(ttext, "website") "`t" find(ttext, "address") "{Enter}"
Return
find(ttext, key) {
RegExMatch(ttext, "i)" key ":\h*(\w+)", match)
Return match1
}