Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Auto-Compile scripts at start


  • Please log in to reply
2 replies to this topic
toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I need to compile a lot of my small scripts. Since I need to specify some comand line options for the compiler, I used a second script in the past to store and pass these parameters to the compiler. This was not very elegant, since I had to adjust the second script if the scripts file name changed and these compile scripts doubled the number of files in my folders.

So I came up with this small auto-compile code.
It will compile your script at start.

After I have tested my scripts and it is time to create a compiled version I add this code to the beginning of the script. This way I can edit the script for small changes and get the compiled version quickly, while everything is in a single file.
If not A_IsCompiled
  {
    ;find compiler
    SplitPath, A_AhkPath ,, OutDir, , , 
    Compiler = %OutDir%\Compiler\Ahk2Exe.exe
    IfNotExist %Compiler%
      {
        MsgBox, 16, Compiling, Compiler couldn't be found at:`n%Compiler%
        ExitApp
      }
    
    ;get script name
    SplitPath, A_ScriptName , , , , OutNameNoExt
    
    ;compile script
    RunWait, %Compiler% /in "%OutNameNoExt%.ahk" /out "%OutNameNoExt%.exe" /pass 123, %A_ScriptDir%, Hide
    
    ;give feedback
    MsgBox,64,Done with compiling,Compiled:`n%OutNameNoExt%.ahk -> %OutNameNoExt%.exe
    ExitApp
  }

Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

  • Guests
  • Last active:
  • Joined: --
Nice one! You might want to add
[...]/icon "%OutNameNoExt%.ico"[...]


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I generally don't have icons for my scripts, thus I leave this up to the user to add this option for the compiler.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.