Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created October 3, 2013 19:05
Show Gist options
  • Save tmplinshi/6815240 to your computer and use it in GitHub Desktop.
Save tmplinshi/6815240 to your computer and use it in GitHub Desktop.
Run/Compile ahk in Sublime Text window with hotkey.
ahk_dir = D:\Program Files\AutoHotkey
exe_ahkANSI = %ahk_dir%\AutoHotkeyA32.exe
exe_ahkUnicode = %ahk_dir%\AutoHotkeyU32.exe
exe_ahk2exe = %ahk_dir%\Compiler\Ahk2Exe.exe
; Hotkey in Sublime Text Window
#IfWinActive, ahk_class PX_WINDOW_CLASS
; ----------------------- Run
F5::
; Get script path from window title
WinGetTitle, title
fpath_full := RegExReplace(title, " - Sublime Text \d( \(UNREGISTERED\))?$")
fpath := RegExReplace(title, "\\[^\\]*$")
; Read ini settings
IniRead, ahk_version, %fpath_full%, config, ahk_version, % A_Space
; Run
if ahk_version in Unicode,ANSI
Run, % (exe_ahk%ahk_version%) A_Space """" fpath_full """", %fpath%
else
Run, "%fpath_full%", %fpath%
return
; ----------------------- Compile
^F5::
; Get script path from window title
WinGetTitle, title
fpath_full := RegExReplace(title, " - Sublime Text \d( \(UNREGISTERED\))?$")
fpath := RegExReplace(title, "\\[^\\]*$")
if ( SubStr(fpath_full, -3) != ".ahk" )
{
MsgBox, 48, Compile, Not a .ahk file, compile canceled.
return
}
; Read ini settings
IniRead, bin, %fpath_full%, config, bin, % A_Space
IniRead, ahk_version, %fpath_full%, config, ahk_version, % A_Space
IniRead, icon, %fpath_full%, config, icon, % A_Space
; Set Options_bin
if bin !=
Options_bin = /bin "%bin%"
else if ahk_version in Unicode,ANSI
Options_bin = /bin "%ahk_dir%\Compiler\%ahk_version% 32-bit.bin"
else
Options_bin =
; Set Options_icon
if icon
Options_icon = /icon "%icon%"
else
Options_icon =
; Compile from command line
ToolTip, Compiling...
RunWait, %exe_ahk2exe% /in "%fpath_full%" %Options_icon% %Options_bin%, %fpath%
ToolTip
; Run it after compile
MsgBox, 36, Run compiled exe, Compile finish! Run it now?
IfMsgBox Yes
Run, % SubStr(fpath_full, 1, -3) "exe", % fpath
return
#IfWinActive
@tmplinshi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment