Need assistance with one last script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
paul1965
Posts: 25
Joined: 27 Feb 2021, 08:06

Need assistance with one last script

09 Apr 2021, 21:43

Okay, I've been having some fun with AHK, and currently have a script that opens 2 of my favorite images using XnView then minimizes them. Another script runs and restores the left side image, then clicks File, Recent Images, and selects a third image. This script runs every day Monday thru Friday, so the image on the left always alternates and the image on the right stays constant. On Saturday, another script runs that launches a third image that is also part of the Recent Images (if 997 exists it opens 998, if 998 exists it opens 997). What I would like to do with my last script, is be able to close the third image and leave the other two in the same order. The challenge I've run into is that since the week days are an odd number, the third, and right most image is never the same. One week it will be image 997, the next it will be 998. Any ideas on how to get AHK to close the right most window regardless of it's title? I did write this code that worked as long as it was launched using my right side monitor. Buy as soon as I moved the folder to my left monitor, it didn't work.

Code: Select all

#NoEnv  ; 
#singleinstance ignore ;
DetectHiddenWindows, On ;
SetTitleMatchMode, 2 ;

MouseMove, -1600, 1500 ;
Sleep, 1500 ;
Click

MouseMove, 655, 880 ;
Click
paul1965
Posts: 25
Joined: 27 Feb 2021, 08:06

Re: Need assistance with one last script

09 Apr 2021, 21:52

Now that I think more about it, maybe the script folder position won't matter. I have a few other scripts the use position mouse clicks and those all work as expected when the script folder isn't even open. I will try merging this code into my Monday script and see what happens.
paul1965
Posts: 25
Joined: 27 Feb 2021, 08:06

Re: Need assistance with one last script

12 Apr 2021, 07:30

My script ran as scheduled but did not work, as the right most XnView window was still open today. Can anyone point me in the right direction on how to get AHK to always close the right most window regardless of its title?
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Need assistance with one last script

12 Apr 2021, 08:03

You can loop through all windows (use winget,list) that show pictures and use WinGetPos to find the rightmost window (biggest X)
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Need assistance with one last script

12 Apr 2021, 08:05

Code: Select all

If !WinExist("ahk_exe xnviewmp.exe") ; XnView MP
 Return
WinActivate
SetKeyDelay, 40
Loop {
 WinGetActiveTitle, wTitle
 If !(browser := Instr(wTitle, ":\"))
  Send ^{Tab}
} Until browser
Send ^{Tab 3}
WinGetActiveTitle, wTitle
Send % Instr(wTitle, ":\") ? "" : "^w"
paul1965
Posts: 25
Joined: 27 Feb 2021, 08:06

Re: Need assistance with one last script

12 Apr 2021, 12:35

mikeyww wrote:
12 Apr 2021, 08:05

Code: Select all

If !WinExist("ahk_exe xnviewmp.exe") ; XnView MP
 Return
WinActivate
SetKeyDelay, 40
Loop {
 WinGetActiveTitle, wTitle
 If !(browser := Instr(wTitle, ":\"))
  Send ^{Tab}
} Until browser
Send ^{Tab 3}
WinGetActiveTitle, wTitle
Send % Instr(wTitle, ":\") ? "" : "^w"

Thanks @mikeyww but this one gave me some problems. I have 3 XnView windows open, and this seemed to get stuck in a loop doing something with them, but I can't really tell what. I could see it rapidly cycling thru all the windows, but nothing happened afterwards and I had to manually kill the script.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Need assistance with one last script

12 Apr 2021, 13:58

These are tabs rather than separate program windows. You may need to adjust to fit your situation. The idea is that it navigates through tabs until it finds the XnView browser tab. It then navigates to the next tab three times, and closes that tab. If your XnView does not have a browser tab, or if its window title differs, you may need to adjust. If you run Window Spy, it will show you the window's complete title.
paul1965
Posts: 25
Joined: 27 Feb 2021, 08:06

Re: Need assistance with one last script

12 Apr 2021, 15:06

mikeyww wrote:
12 Apr 2021, 13:58
These are tabs rather than separate program windows. You may need to adjust to fit your situation. The idea is that it navigates through tabs until it finds the XnView browser tab. It then navigates to the next tab three times, and closes that tab. If your XnView does not have a browser tab, or if its window title differs, you may need to adjust. If you run Window Spy, it will show you the window's complete title.
Ah I missed that. I have XnView set to open separate windows, so I'll play around with it bit later. Thanks!
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Need assistance with one last script

12 Apr 2021, 16:15

You could use WinGet to get the matching window list, and then determine which of those windows to close with WinClose.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, hedehede81, ThePeter and 244 guests