How can I make a script start other scripts? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

How can I make a script start other scripts?

Post by LAPIII » 26 Jan 2022, 09:40

My idea is to put a launching script into my AutoHotkey start up folder. I need to know where that is located, and I will store my other scripts in C:\Users\LPIII\Documents\AutoHotkey.

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: How can I make a script start other scripts?

Post by boiler » 26 Jan 2022, 09:51

LAPIII wrote: How can I make a script start other scripts?
You can run other scripts from your script using the Run command.

LAPIII wrote: My idea is to put a launching script into my AutoHotkey start up folder. I need to know where that is located...
I don't know what you mean by your "AutoHotkey start up folder." To start scripts automatically upon Windows startup, put a shortcut to your script in the Windows Startup folder. It's not a good practice to put the actual script file in that folder instead of a shortcut to the file. To create a shortcut, right-click on your script file in File Explorer and select "Create shortcut."

LAPIII wrote: ...and I will store my other scripts in C:\Users\LPIII\Documents\AutoHotkey.
Use the full path to those scripts when you use the Run command in your main script. Or, if your main script is located in the same directory as those other scripts (which can be the case since you are only putting a shortcut to the script in the Startup directory), then you don't need a path at all unless your script changes the default working directory.

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: How can I make a script start other scripts?

Post by LAPIII » 26 Jan 2022, 15:02

Is the following correct:

Code: Select all

#IfWinActive, ahk_exe AM4.exe
Run C:\Users\LPIII\Desktop\WSS.ahk
For adding scripts to the Run command, is there an alternative to &&?

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: How can I make a script start other scripts?

Post by boiler » 26 Jan 2022, 16:10

LAPIII wrote: Is the following correct:

Code: Select all

#IfWinActive, ahk_exe AM4.exe
Run C:\Users\LPIII\Desktop\WSS.ahk
No, that is not correct. The #IfWinActive directive applies to hotkeys and the like, not to regular commands. What are you trying to accomplish? Do you want it to run that script the first time the AM4.exe becomes active? Or when exactly?

LAPIII wrote: For adding scripts to the Run command, is there an alternative to &&?
Using && is not a valid approach for running multiple programs/scripts. What you saw in the documentation is for running more than one command in a command (%ComSpec%) window that was opened by the Run command, not for running more than one program or script with the Run command. To run more than one script, you just use more than one Run command on separate lines.

For example, instead of this:

Code: Select all

Run notepad.exe && mspaint.exe
...you would do this:

Code: Select all

Run notepad.exe
Run mspaint.exe

LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: How can I make a script start other scripts?

Post by LAPIII » 26 Jan 2022, 22:19

boiler wrote:
26 Jan 2022, 16:10

No, that is not correct. The #IfWinActive directive applies to hotkeys and the like, not to regular commands. What are you trying to accomplish? Do you want it to run that script the first time the AM4.exe becomes active? Or when exactly?
Yes the first time AM4.exe becomes active.

User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: How can I make a script start other scripts?  Topic is solved

Post by boiler » 26 Jan 2022, 22:20

Code: Select all

WinWaitActive, ahk_exe AM4.exe
Run C:\Users\LPIII\Desktop\WSS.ahk

Post Reply

Return to “Ask for Help (v1)”