Merging two scripts in one file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wise_mike
Posts: 90
Joined: 28 Feb 2014, 01:37

Merging two scripts in one file

03 Dec 2018, 09:32

I have 2 scripts I want to merge in one file, however when I put them together, only the first one gets executed:

Script 1:

Code: Select all

#if WinActive("ahk_exe program.EXE")
#Persistent
Loop
{
WinWaitActive, Wizard
Send, !{F4}
}

Return
Script 2:

Code: Select all

#if WinActive("ahk_exe program2.EXE")

#Persistent
Loop
{
	WinWait, ahk_class bosa_sdm_Mso96
	; IfWinNotActive,  ahk_class bosa_sdm_Mso96, ,WinActivate, ahk_class bosa_sdm_Mso96
	; WinWaitActive, ahk_class bosa_sdm_Mso96
	; Sleep, 0
	ControlMove, RichEdit20W6, 20, 850, 750, 25   ;Adress box
	ControlMove, SysTreeView321, , , 800, 700
	ControlMove, TreeViewCFParent1, , , 1000, 700
	ControlMove, SysTreeView322, , , 800, 700
	ControlMove, TreeViewParent1, , , 760, 940
	WinMove, ahk_class bosa_sdm_Mso96, , 600, 50, 1000, 900 ; 900 width
}

Return
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: Merging two scripts in one file

03 Dec 2018, 10:25

try this maybe?

Code: Select all

#Persistent

#if WinActive("ahk_exe program.EXE")
Loop
{
	WinWaitActive, Wizard
	Send, !{F4}
}

#if WinActive("ahk_exe program2.EXE")
Loop
{
	WinWait, ahk_class bosa_sdm_Mso96
	; IfWinNotActive,  ahk_class bosa_sdm_Mso96, ,WinActivate, ahk_class bosa_sdm_Mso96
	; WinWaitActive, ahk_class bosa_sdm_Mso96
	; Sleep, 0
	ControlMove, RichEdit20W6, 20, 850, 750, 25   ;Adress box
	ControlMove, SysTreeView321, , , 800, 700
	ControlMove, TreeViewCFParent1, , , 1000, 700
	ControlMove, SysTreeView322, , , 800, 700
	ControlMove, TreeViewParent1, , , 760, 940
	WinMove, ahk_class bosa_sdm_Mso96, , 600, 50, 1000, 900 ; 900 width
}

Return
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: Merging two scripts in one file

03 Dec 2018, 10:48

try
IfWinactive, ahk_exe program.EXE

also try removing the loop
wise_mike
Posts: 90
Joined: 28 Feb 2014, 01:37

Re: Merging two scripts in one file

03 Dec 2018, 10:51

Neither working, sorry.
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Merging two scripts in one file

03 Dec 2018, 14:33

Hi, if you want to use loops then you will need to merge them and check for windows activation inside the loops, otherwise it gets stuck in the first loop that meets the conditions.
wise_mike
Posts: 90
Joined: 28 Feb 2014, 01:37

Re: Merging two scripts in one file

03 Dec 2018, 14:42

Thanks, can you edit the script as suggested? I tried removing both the loops, but I think I am doing something wrong.
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Merging two scripts in one file

03 Dec 2018, 14:48

Untested

Code: Select all

Loop
{
	if WinActive("ahk_exe program.EXE")
	{
		WinWaitActive, Wizard
		Send, !{F4}
	}
	else if WinActive("ahk_exe program2.EXE")
	{
		WinWait, ahk_class bosa_sdm_Mso96
		; IfWinNotActive,  ahk_class bosa_sdm_Mso96, ,WinActivate, ahk_class bosa_sdm_Mso96
		; WinWaitActive, ahk_class bosa_sdm_Mso96
		; Sleep, 0
		ControlMove, RichEdit20W6, 20, 850, 750, 25   ;Adress box
		ControlMove, SysTreeView321, , , 800, 700
		ControlMove, TreeViewCFParent1, , , 1000, 700
		ControlMove, SysTreeView322, , , 800, 700
		ControlMove, TreeViewParent1, , , 760, 940
		WinMove, ahk_class bosa_sdm_Mso96, , 600, 50, 1000, 900 ; 900 width
	}
	sleep 100	;change it to whatever duration you deem fit
}
wise_mike
Posts: 90
Joined: 28 Feb 2014, 01:37

Re: Merging two scripts in one file

03 Dec 2018, 15:14

It worked for the first executed program only, but no the other.
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Merging two scripts in one file

03 Dec 2018, 15:16

I see. Perhaps something is wrong with the conditions for program2 or there is an error in that block of code. Put and msgbox in it to see if it even executes, and if it does you will have to check the rest of that code block for errors.
wise_mike
Posts: 90
Joined: 28 Feb 2014, 01:37

Re: Merging two scripts in one file

03 Dec 2018, 15:22

OK, thanks a lot..

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest, Bing [Bot], bowie1123 and 326 guests