Page 1 of 1

Running multiple versions of AHK2

Posted: 25 Jul 2020, 18:58
by Kapitano
The must have been discussed before, but I can't find it, so....

I'm running two versions of AHK2, in different folders. Folder "AutoHotKey" contains "AutoHotKeyU64.exe" (a108) and 60+ legacy scripts. Folder "AHK_DEV" contains "AutoHotKey64U_DEV.exe", renamed from whichever version is the most recent, plus all the new scripts, and those legacy scripts which I've so far updated. All scripts in "AHK_DEV" have the extension ".ahk_DEV", and are associated with "AutoHotKey64U_DEV.exe".

When all the legacy scripts are updated, I can delete the old versions and restore the filenames and associations to default.

But... Is there a simpler, more elegant way to do all this?

Re: Running multiple versions of AHK2

Posted: 25 Jul 2020, 20:52
by lexikos
You can instead associate .ahk files with a launcher script which runs the appropriate exe based on whatever condition you want (e.g. the location of the file, or a comment or directive indicating the required version).

Re: Running multiple versions of AHK2

Posted: 26 Jul 2020, 03:16
by Kapitano
Just a thought, but could it be possible to add a "preferred executor" function to AHK scripts. Something like:

Code: Select all

#RunWith "C:\Software\AutoHotkey2 a118\AutoHotKeyU64.exe"

Code: Select all

#RunWith "C:\Software\AutoHotKey1.1\AutoHotKey.exe"

Re: Running multiple versions of AHK2

Posted: 26 Jul 2020, 05:55
by lexikos
How do you think it will work? Something has to read the directive. You're probably thinking that AutoHotkey.exe itself would do it, but that obviously won't be v2.0-a118 or v1.1.33.02, since those versions have already been released without that directive. I prefer the method I already mentioned. There's no need for a directive - the launcher script can read comments.

By the way, including the path of the interpreter in a script is an old idea used on Unix.

With your example, every user must have the appropriate interpreter installed in the same location. Better to specify only the requirements of the script, and let the launcher determine what to do based on what's "installed" (or known by the launcher). My intention is for the installer to include a script that does this, based on #requires, a comment with version information, or checking for tell-tales in the script (such as #NoEnv -> v1). Anyone could write or maintain a launcher such as this. Your suggestion is even simpler to write a script for. For example:

Code: Select all

code := FileRead(A_Args[1])
if RegExMatch(code, "i)#RunWith\s+(.*?)", match)
	exe := match.1
else
	exe := '"' A_AhkPath '"'
Run exe ' "' A_Args[1] '"'
This assumes the script filename is passed as a command line parameter. This can be registered for .ahk files in place of AutoHotkey.exe (but when doing so, the command line must include the AutoHotkey.exe you wish to run it with). It does no error-checking, it expects double quotes around the path (if it contains spaces), it does not support additional command line parameters (in A_Args) or paths relative to the script being launched, and of course #RunWith must be inside a comment for the script to work. If there's no #RunWith, it uses whichever exe you ran the launcher with (if not compiled).