Last active
July 23, 2020 16:34
-
-
Save davebrny/17a64afe1233a454a5842d96317dce99 to your computer and use it in GitHub Desktop.
📦 (autohotkey) - compile an .ahk file to .exe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;# compile file(s) passed to this script | |
path_total = %0% | |
loop, % path_total | |
{ | |
ahk_path := %a_index% ; get cmd line parameters | |
if inStr(ahk_path, "~") ; if drag & drop was used | |
{ | |
loop %ahk_path%, 1 ; convert from short path | |
ahk_path := a_loopFileLongPath | |
} | |
if (path_total > 1) ; if more than 1 file | |
compile(ahk_path, , , "wait") | |
else compile(ahk_path) | |
} | |
exitApp ; end of script ------------------ | |
compile(ahk_file="", exe_file="", icon_file="", wait="") { | |
splitPath, a_ahkPath, , ahk_dir | |
ahk2exe := """" ahk_dir . "\Compiler\Ahk2Exe.exe""" | |
;# .ahk input | |
if (ahk_file = "") | |
ahk_file := a_scriptFullPath | |
ahk_in := " /in """ . ahk_file . """" | |
splitPath, ahk_file, , file_dir, file_ext, name_no_ext | |
if (file_ext != "ahk") | |
return ; dont continue | |
;# .exe output | |
if (exe_file = "") | |
exe_file := file_dir "\" name_no_ext ".exe" | |
exe_out := " /out """ . exe_file . """" | |
;# script icon | |
if (icon_file = "") | |
{ | |
if fileExist(file_dir "\" name_no_ext ".ico") ; if matching icon in the script directory | |
icon_file := file_dir "\" name_no_ext ".ico" | |
; else icon_file := script_icon(file_dir "\" name_no_ext) ; search for an icon: git.io/vyBcQ | |
} | |
if (icon_file = "") | |
exe_icon := "" | |
else exe_icon := " /icon """ . icon_file . """" | |
; -------------------------------------------------- | |
run, % ahk2exe . ahk_in . exe_out . exe_icon, , hide | |
; -------------------------------------------------- | |
if (wait != "") ; wait until .exe is compiled | |
{ | |
splitPath, exe_file, , file_dir, , name_no_ext | |
loop, | |
sleep 500 | |
until (fileExist(file_dir "\" name_no_ext ".exe")) | |
or (a_index = 6) ; 3 seconds | |
or (winExist("Ahk2Exe Error ahk_exe Ahk2Exe.exe")) | |
} | |
} | |
/* | |
[script info] | |
version = 1.1 | |
description = compile an .ahk file to .exe | |
author = davebrny | |
source = https://gist.github.com/davebrny/17a64afe1233a454a5842d96317dce99 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compile
usage
- add compile.ahk to your user library.
- if
exe_file
is left empty then the compiled .exe will be created with the same name and directory as the .ahk file.- if
icon_file
is left empty then it will look in the script directory for an icon matching the script name.- for a more icon options download script_icon.ahk and uncomment line 46
drag & drop
if drag & drop is enabled then scripts can be dragged onto compile.ahk.
you can also create a shortcut to compile.ahk and add it to a few different locations and then drag your scripts onto the shortcut instead.
launcher
scripts can be compiled by using launchers such as launchy or keypirinha to send the path to the script:
- search for compile.ahk
- press the
tab
key when compile.ahk is at the top of the list- paste the path of the ahk script you want compiled and then press
enter
Â
compile selected file(s)
- select files in file explorer and use  ctrl alt shift + c  to compile them