About asterisk in window title

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Okapi
Junior Coder
Posts: 28
Joined: Wed Dec 29, 2010 1:22 am

About asterisk in window title

Post by Okapi » Thu Dec 30, 2010 9:41 am

Hi, in this part of script, I want to use asterisk wildcard to specify just a part of window title, but it doesn't work

Code: Select all

GetActiveWindow>title,x,y
If>{(%title%="google*") OR (%title%="yahoo*")}
  //do something
Endif
This one doesn't work too :

Code: Select all

Let>title1=google*
Let>title2=yahoo*
GetActiveWindow>title,x,y
If>{(%title%=%title1%) OR (%title%=%title2%)}
  //do something
Endif
Thanks for help

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 30, 2010 10:45 am

The asterisk is used only within the Window functions. But above you are comparing strings. What you want to do is do a substring check or RegEx match. E.g.:

Code: Select all

GetActiveWindow>title,x,y
Position>google,title,1,pGoogle
Position>yahoo,title,2,pYahoo
If>{(%pGoogle%>0) OR (%pYahoo%>0)}
  //do something
Endif
The Position command returns the starting position of one string in another. So if google is in title you will get a result of greater than zero. Look at the Position command in the help file.

Note that the above does not consider case.

You could shorten the above and make it case insensitive in one line using:

Code: Select all

GetActiveWindow>title,x,y
If>{(Pos("google",lower(%title%))>0) OR (Pos("yahoo",lower(%title%))>0)}
  //do something
Endif
Another way to do it is to use RegEx:

Code: Select all

GetActiveWindow>title,x,y
RegEx>google|yahoo,title,0,matches,num_matches,0
If>num_matches>0
  //do something
Endif
Note that by default regex is case insensitive so the above is a little simpler.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Okapi
Junior Coder
Posts: 28
Joined: Wed Dec 29, 2010 1:22 am

Post by Okapi » Thu Dec 30, 2010 12:13 pm

Okay. First one doesn't work, the tow others work perfect. Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 30, 2010 1:39 pm

The first one DOES work (it does what is asked of it) but is case sensitive so may not work for you. The others are not case sensitive.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts