Sign in to follow this  
Followers 0
amir

Check the content of an active window?

3 posts in this topic

Hi,

I'm trying to write my very first script.

I want the script to edit a text file that is located at the installation path of an application i'm using.

Anyway, as you can see below, after i've opened the text file in notepad, i'm trying to find the string i want to edit, using ^f.

If the text file i'm editing contains the string i'm looking for, then the script works well, but how can i handle a situation in which the FIND function in notepad, is unable to locate the string?

How can i identify this situation in the script?

I need to know what happen after i press the FIND button, was the string found or did an error message appear.

Here's what i have so far:

$MyappInstallationPath = RegRead("HKCU\Software\myapp\app","MyAppPath") ;Fetching the path from registry

Run("notepad.exe")

WinWaitActive("Untitled - Notepad")

Send("^o") ;opening the OPEN FILE dialog

send($MyappInstallationPath ) ;Entering the path for the file

send("\settings.txt") ;Entering the file name

send("!o") ;Pressing the OPEN button to open the file

send("^f") ;Opening the FIND dialog

send("viewmode") ;Entering the string to find

send("!f") ;Pressing the FIND button

Send("!{F4}") ;Closing the FIND dialog

Send("{RIGHT}")

send("+{END}")

Send("{BS}")

Send("1")

send("^s")

send("!f")

send("x")

Share this post


Link to post
Share on other sites



Instead of doing a tedious automation concept, just do a fileread() of the text file and use StringInStr() to check the read contents for your text.

$MyappInstallationPath = RegRead("HKCU\Software\myapp\app","MyAppPath")
If Not @error And $MyappInstallationPath <> '' Then
    $content = FileRead($MyappInstallationPath & '\settings.txt')
    If Not @error And StringInStr($content, 'viewmode') Then
        MsgBox(0x40040, @ScriptName, 'Found "viewmode"')
    EndIf
EndIf

:whistle:

Share this post


Link to post
Share on other sites

Instead of doing a tedious automation concept, just do a fileread() of the text file and use StringInStr() to check the read contents for your text.

$MyappInstallationPath = RegRead("HKCU\Software\myapp\app","MyAppPath")
If Not @error And $MyappInstallationPath <> '' Then
    $content = FileRead($MyappInstallationPath & '\settings.txt')
    If Not @error And StringInStr($content, 'viewmode') Then
        MsgBox(0x40040, @ScriptName, 'Found "viewmode"')
    EndIf
EndIf

:whistle:

THANKS MHz !!!!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0