How I run another AHK script from another AHK script

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
xMaxrayx
Posts: 214
Joined: 06 Dec 2022, 02:56
Contact:

How I run another AHK script from another AHK script

Post by xMaxrayx » 25 Dec 2023, 04:10

Hi ,I tired this but didn't work

Code: Select all

Run "A_AHKPath" " MsgBox()"
does ahk support arguments?
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
xMaxrayx
Posts: 214
Joined: 06 Dec 2022, 02:56
Contact:

Re: How I run another AHK script from another AHK script

Post by xMaxrayx » 25 Dec 2023, 04:32

ok this worked but it says script file not found

Code: Select all

Run A_AHKPath ' -MsgBox("Hi")'
Last edited by xMaxrayx on 25 Dec 2023, 05:02, edited 1 time in total.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
Datapoint
Posts: 303
Joined: 18 Mar 2018, 17:06

Re: How I run another AHK script from another AHK script

Post by Datapoint » 25 Dec 2023, 05:01

xMaxrayx wrote:
25 Dec 2023, 04:32
it says script file not found
The error is saying -MsgBox("Hi") is not a script file.

It is expecting a file path like:

Code: Select all

Run A_AHKPath ' C:\path\to\some\file.ahk'
niCode
Posts: 315
Joined: 17 Oct 2022, 22:09

Re: How I run another AHK script from another AHK script

Post by niCode » 25 Dec 2023, 05:03

Does this work for you?

Code: Select all

Run('AutoHotkey.exe /restart ' A_ScriptName ' ' MsgBox('hi'))
If you want to pass a string as a parameter and check it to conditionally do something, see this page.
User avatar
xMaxrayx
Posts: 214
Joined: 06 Dec 2022, 02:56
Contact:

Re: How I run another AHK script from another AHK script

Post by xMaxrayx » 25 Dec 2023, 05:31

Datapoint wrote:
25 Dec 2023, 05:01
xMaxrayx wrote:
25 Dec 2023, 04:32
it says script file not found
The error is saying -MsgBox("Hi") is not a script file.

It is expecting a file path like:

Code: Select all

Run A_AHKPath ' C:\path\to\some\file.ahk'


Yeah thanks, I dont want save as file because it's bad for hard-drive if it was spammy save.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
xMaxrayx
Posts: 214
Joined: 06 Dec 2022, 02:56
Contact:

Re: How I run another AHK script from another AHK script

Post by xMaxrayx » 25 Dec 2023, 05:34

niCode wrote:
25 Dec 2023, 05:03
Does this work for you?

Code: Select all

Run('AutoHotkey.exe /restart ' A_ScriptName ' ' MsgBox('hi'))
If you want to pass a string as a parameter and check it to conditionally do something, see this page.



Oh yea thanks for some reason it still gives me "didn't find the file"





so I did this:
  • - create new empty ahk file (I namm-ed it as DebugEmpty.ahk)

    - I use this code

    Code: Select all

    Run('AutoHotkey.exe /force ' (A_ScriptDir "\DebugEmpty.ahk") ' ' MsgBox('hi'))
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
Smile_
Posts: 859
Joined: 03 May 2020, 00:51

Re: How I run another AHK script from another AHK script

Post by Smile_ » 25 Dec 2023, 15:16

? :arrow: Example 8

Code: Select all

#Requires AutoHotkey v2

ExecScript('Msgbox("Hi")')
ExecScript('
(
Msgbox("Hi again")
Msgbox("and again Hi")
)')

ExecScript(Script, Wait := True) {
    shell := ComObject("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
    exec.StdIn.Write(Script)
    exec.StdIn.Close()
    if Wait
        return exec.StdOut.ReadAll()
}
User avatar
Datapoint
Posts: 303
Joined: 18 Mar 2018, 17:06

Re: How I run another AHK script from another AHK script

Post by Datapoint » 25 Dec 2023, 23:15

xMaxrayx wrote:
25 Dec 2023, 05:31
Yeah thanks, I dont want save as file because it's bad for hard-drive if it was spammy save.
I wasn't suggesting that. I was showing you why you were getting an error.
User avatar
xMaxrayx
Posts: 214
Joined: 06 Dec 2022, 02:56
Contact:

Re: How I run another AHK script from another AHK script

Post by xMaxrayx » 27 Dec 2023, 11:23

Smile_ wrote:
25 Dec 2023, 15:16
? :arrow: Example 8

Code: Select all

#Requires AutoHotkey v2

ExecScript('Msgbox("Hi")')
ExecScript('
(
Msgbox("Hi again")
Msgbox("and again Hi")
)')

ExecScript(Script, Wait := True) {
    shell := ComObject("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
    exec.StdIn.Write(Script)
    exec.StdIn.Close()
    if Wait
        return exec.StdOut.ReadAll()
}
Hi thanks ,do you know how to run the new script under different name other than *, I tired replace it with another name but failed.

it seems more easy with Run class
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
Smile_
Posts: 859
Joined: 03 May 2020, 00:51

Re: How I run another AHK script from another AHK script

Post by Smile_ » 29 Dec 2023, 03:47

That * asterik is not meant for a file name, it is meant to execute a given code as a new process without the need to create an ahk script.
If you like to run a new ahk script, you just use Run(Path/To/Your/New/Script) in the case that AutoHotkey is installed on your system.
User avatar
xMaxrayx
Posts: 214
Joined: 06 Dec 2022, 02:56
Contact:

Re: How I run another AHK script from another AHK script

Post by xMaxrayx » 15 May 2024, 03:41

Smile_ wrote:
29 Dec 2023, 03:47
That * asterik is not meant for a file name, it is meant to execute a given code as a new process without the need to create an ahk script.
If you like to run a new ahk script, you just use Run(Path/To/Your/New/Script) in the case that AutoHotkey is installed on your system.
I see thank you , I found this mothed with A_ScriptName

Code: Select all


ExecScript('
(
A_ScriptName := "Pizza store"
Msgbox("Hi again")
Msgbox("and again Hi")
)')

ExecScript(Script, Wait := True) {
    shell := ComObject("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
    exec.StdIn.Write(Script)
    exec.StdIn.Close()
    if Wait
        return exec.StdOut.ReadAll()
}


-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
Post Reply

Return to “Ask for Help (v2)”