Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i have two functioning scripts that i want to merge into a single AHK File. My problem is that when i combine both scripts, the second script doesnt function or causes an error on script 1. Either way, script 2 ist not functioning at all.

Here are some facts: Script 1 = a simple menu script where 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

Any help is appreciated.

Kind Regards,

Mikey

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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):

popupMenuScriptStartup:

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

GoSub popupMenuScriptStartup
share|improve this answer
    
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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