I have two functioning scripts. When I combine them, the second doesn't function or causes an error on script 1.

Script 1 = A simple menu script I want to assign hotkeys to. Script 2 = A small launcher script from a user named Tertius in AutoHotkey forum.

See the codes merged: http://pastebin.com/uuaDKNXu

See Keywords.ini needed in script 2: http://pastebin.com/LtybdSxG

See Script 1: http://pastebin.com/Wf3bMWd4

See Script 2: http://pastebin.com/sFjVAGqE


I think the problem is that each script has an auto-execute section, but only the first section is being processed. With autohotkey, the auto-execute section ends the first time the return keyword or a hotkey label like $Tab:: is processed.

I made a new pastebin that turns the auto-execute section from the second script into a function, and then calls it with GoSub.

I created the function by putting this line at the start of script 1 (line 102 in the linked script):


Then we call this function on line 10 of the script:

GoSub popupMenuScriptStartup
  • Thanks Ranomore, your corrections solved the problem and the merged script is fully functional now. Great explanation too! – Mikey Mar 25 '12 at 10:39

I found a couple of alternative methods for using multiple AHK scripts: #include and Run

  • If the second file is a collection of methods/functions, you can simply include it by using

    #include FullPathToFile.ahk

    at the top of your file. You can then call all your methods from the second script in the first as needed.

  • If the second file is a standalone script that includes initialization that needs to be run as part of the startup, you could just Run run the second script from the first. You'd also want to close it when the first script exits:

    Run FullPathToSecondScript.ahk,,, pidToCloseOnExit
    WinClose, ahk_pid, pidToCloseOnExit
    Exit App

Because of the nature of the script you're trying to add, I don't think the first option would work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.