Jump to content

Title text match with spaces


Recommended Posts

I am trying to rebuild an old single signon script that has been giving us a bit of trouble lately.  I didn't write it and it was written in another script language.  If the target program is already open it will have the current user's last name as part of the window text, which I am trying to compare against the user name to see if I should just WinActivate or Process Close and start the program over.  I will be provided the username like "jones", or "smith" and the title check works fine for last names (with no spaces), but if the last name DOES contains spaces, say "Nom De Plume", then all I will be given as a username is "nomdeplume".  Is there any way (via a regex maybe) that I can still check the text on the screen and somehow ?  I have been reading about the Advanced (4) mode of WinTitleMatchMode, but it is over my head.  Any help is appreciated.  Here is a small reproducer script:

Opt("WinTitleMatchMode", -1)

Run("Notepad")
WinWait("[CLASS:Notepad]", "", 10)
Send ("Smith" & @CRLF & "Jones" & @CRLF & "Nom De Plume" & @CRLF)

If WinExists("[CLASS:Notepad]", "jones") Then
    MsgBox(0,"FOUND","Found Jones")
EndIf

If WinExists("[CLASS:Notepad]", "nomdeplume") Then
    MsgBox(0,"FOUND","Found Nom De Plume")
EndIf

 

Edited by MuffinMan
Link to comment
Share on other sites

Well, I have something now that certainly seems to work, I'll start testing and see how this holds up; still interested if anyone has any better solutions.

Opt("WinTitleMatchMode", -1)

Run("Notepad")
WinWait("[CLASS:Notepad]", "", 10)
Send ("Smith" & @CRLF & "Jones" & @CRLF & "Nom De Plume" & @CRLF)

$WinText = StringStripWS(WinGetText("[CLASS:Notepad]"),8)

If StringInStr($WinText, "jones") <> 0 Then
    MsgBox(0,"FOUND","Found jones")
EndIf

If StringInStr($WinText, "nomdeplume") <> 0 Then
    MsgBox(0,"FOUND","Found Nom De Plume")
EndIf

 

Link to comment
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
 Share

×
×
  • Create New...