|
Post by moatmai on Mar 31, 2022 16:39:30 GMT
Using Mini Mouse Macro Pro, I am trying to check whether a window exists by targeting its title, i.e.
6 | IF | WINDOW TITLE | Page Info | EXIST | CONTINUE
However, this does not work because the actual title is "Page Info — <some URL>", where <some URL> changes depending on the page from which I'm invoking the Page Info window.
I was hoping to use something like "Page Info*" to do a wildcard match, but that doesn't work.
Can anyone suggest what could I do to get the Macro to work the way I need it to?
|
|
|
Post by Steve on Apr 1, 2022 22:10:25 GMT
Hi moatmai Yes we can do this but its not pretty. MMM at the moment has very little in the way of string manipulation which makes problems like this complicated. At this stage with version 8.3.3.0 we need to rely on external commands to feed the variables in for the window titles. I don't have any give within the 'WINDOW TITLE' condition for wildcarding/fuzzy matching but i will look into that. Bear with me - this is what I have below: 1 | RUN ACTION | RUN VIA CMD /C | tasklist /fi "imagename eq notepad.exe" /fo list /v > d:\macro\temp\windowlist.txt & findstr "Window Title:" d:\macro\temp\windowlist.txt > d:\macro\temp\windows.txt 2 | IF | FILE | D:\macro\temp\mmm_log.txt | EXIST | FILE DELETE | D:\macro\temp\mmm_log.txt 3 | FOR | EACH | LINE IN | D:\macro\temp\windows.txt | DO 4 | RUN ACTION | DEFINE STRING VARIABLE | %STRING%::%line% 5 | RUN ACTION | RUN VIA CMD /C | for /F "tokens=1,2,*" %a in ("%STRING%") do echo %c>>d:\macro\temp\mmm_log.txt 6 | RUN ACTION | WAIT SECONDS | 1 7 | FOR | NEXT 8 | FOR | EACH | LINE IN | d:\macro\temp\mmm_log.txt | DO 9 | RUN ACTION | DEFINE STRING VARIABLE | %WINDOW_TITLE%::%line% 10 | IF | WINDOW TITLE | %WINDOW_TITLE% | EXIST | MESSAGE PROMPT | Found Window: %WINDOW_TITLE%::%WINDOW_TITLE% EXITS!::0::OK 11 | FOR | NEXT In this example I want to find pizza.txt - Notepad. A new file I opened. Line 1: One way to capture all the window titles is with the old tasklist command. At line 1 we run a command line action to output all the window titles from open notepad.exe windows. We output that to windowlist.txt. After that we run findstr to filter for only the 'Window Title:' lines in the file and output that to another file called windows.txt. The result is a file called windows.txt with the current open notepad text file window titles. It looks like this for my currently open text files: windows.txtWindow Title: windowlist.txt - Notepad Window Title: pizza.txt - NotepadLine 2: We make sure we dont have mmm_log.txt so we delete it. We need that file clean for later on. Line 3: Line 2 is the start of a for loop where we loop over each line in windows.txt. Line 4: We define a new variable %STRING% to contain the contents of the current line of the file (%LINE%). Line 5: We need to trim the 'Window Title: ' away from the string so we are just left with titles. We need another batch command here so we throw it at a windows for /F and print out the 3 to the nth values. Line 6: Here we wait 1 second because the macro runs faster than the command at line 5 and want to ensure that mmm_log.txt is fully populated. Line 7: This is the end of the FOR we started at line 3. At this point we have another file 'mmm_log.txt' with just the window titles. It looks like this: mmm_log.txtwindowlist.txt - Notepad pizza.txt - NotepadLine 8: Line 8 is the start of a for loop where we loop over each line in mmm_log.txt. Line 9: We define a new variable %WINDOW_TITLE% to contain the content of the current line of the file (%LINE%). Line 10: Here we loop for our window title and if we find it I popup a message box to say "Found Window %WINDOW_TITLE%". Line 11: We end the for loop. My windows cmd line is pretty old school and powershell is probably the better tool here to extract the values. If someone has a neater script please please pass it out here. I'd love to see it. Hope this helps. Steve.
|
|
|
Post by moatmai on Apr 2, 2022 0:56:44 GMT
First of all: Thanks for your response! And I appreciate the fact that there actually is a solution.
Second: Oof. That is a lot of work for achieving a fuzzy match ... I thought there was some eay thing I was missing, but apparently I have opened quite the proverbial can of worms.
I think I will have to handle this manually for now. (It is a task I do every one or two months ...)
Hopefully there will be a future version of MMM which will do fuzzy matching. I'll wait until then.
Regards, moatmai
|
|