Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Share the finished AutoHotkey v2 Scripts and libraries you made here. Please put the current version of AutoHotkey v2 you used in Square Brackets at the start of the topic title.
User avatar
boiler
Posts: 5919
Joined: 21 Dec 2014, 02:44

Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by boiler » 28 May 2020, 22:09

I've seen people struggling for an easy way to run AHK v2 files while v1.1 is still installed. This is a simple but effective script that I use to run a v2 script with just one click. It has none of the drawbacks of the other approaches I've seen:
  • No swapping binary files changing your default installation
  • No changes to the registry
  • No new file extensions
  • No changes to right-click menus
  • No dedicated directory for v2 files
  • No need to drag and drop files
Usage:
  • The first time you run the script, it will ask you to select your v2 binary file.
  • Click on an AHK v2 file with your middle mouse button to run that script in v2.
  • If you want to change to a different binary file, select that option by right-clicking on the tray menu.
  • That's it!
Can also be used in reverse -- run v1 files if your main installation is v2. Or run it with any other binary you specify -- ANSI/Unicode, 32/64 bit, AHK_H, AHK 1.0.

There is also a version written in v1 posted in the main section of Scripts and Functions.

Download:
run alt ahk version_v2_raav v1_2.zip
(1.88 KiB) Downloaded 27 times

Changelog:
- v1.0: initial release
- v1.1:
  • Added user selection of bin file (via file selector and ini file)
  • Added selection of new binary file to tray menu
  • Removed reliance on clipboard using TeaDrinker's Explorer_GetSelection() (minor mods for AHK v2)
  • Added check to ensure a file (not folder) was selected per malcev's suggestion
- v1.2:
  • fixed issue where newly selected bin file wouldn't be used before reloading
  • fixed error when attempting to read non-existent ini file
  • updated for AHK v2.0-a112 (make hotkey routine a function, turn off unset warnings)
Last edited by boiler on 28 Jun 2020, 10:25, edited 3 times in total.

Helgef
Posts: 4459
Joined: 17 Jul 2016, 01:02
Contact:

Re: Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by Helgef » 29 May 2020, 05:46

Nice, works well :thumbup:.

Thanks for sharing, cheers.

User avatar
boiler
Posts: 5919
Joined: 21 Dec 2014, 02:44

Re: Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by boiler » 29 May 2020, 06:05

Thanks for the feedback!

User avatar
boiler
Posts: 5919
Joined: 21 Dec 2014, 02:44

Re: Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by boiler » 29 May 2020, 10:52

Updated the first post with an updated version (1.1) including these changes:
  • Added user selection of bin file (via file selector and ini file)
  • Added selection of new binary file to tray menu
  • Removed reliance on clipboard using TeaDrinker's Explorer_GetSelection() per malcev's suggestion
  • Added check to ensure a file (not folder) was selected per malcev's suggestion

User avatar
boiler
Posts: 5919
Joined: 21 Dec 2014, 02:44

Re: Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by boiler » 11 Jun 2020, 22:26

Realized that I attached only the ahk file in the original post for the latest update, not the zip file that includes the icon. Original post updated with zip file.

User avatar
boiler
Posts: 5919
Joined: 21 Dec 2014, 02:44

Re: Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by boiler » 28 Jun 2020, 10:26

Updated first post with updated version 1.2 that includes these changes:
  • fixed issue where newly selected bin file wouldn't be used before reloading
  • fixed error when attempting to read non-existent ini file
  • updated for AHK v2.0-a112 (make hotkey routine a function, turn off unset warnings)

User avatar
vvhitevvizard
Posts: 405
Joined: 25 Nov 2018, 10:15
Location: Russia

Re: Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by vvhitevvizard » 29 Jun 2020, 08:13

thanks for sharing. :thumbup:

Suggestion:
For this line,

Code: Select all

	if (ErrorLevel) || (SubStr(ScriptFilePath, -4) != ".ahk") || (FileExist(ScriptFilePath) = "D")
change it to

Code: Select all

	if (ErrorLevel) || !(ScriptFilePath ~= ".*\.ahk2?$") || (FileExist(ScriptFilePath) = "D")
b/c some ppl use .ahk2 extension for AHKv2.

In the future u might want to analyze any Edit/List/some other fields that have a focus and text caret position in order to be able to run AHK from other File Explorers like Total Commander.

And in general. In order to have it truly v2-aware u gotta avoid using deprecated ErrorLevel in favor of try/catch blocks and use IsSet() instead of #Warn UseUnsetGlobal, Off, #Warn UseUnsetLocal, Off.

User avatar
boiler
Posts: 5919
Joined: 21 Dec 2014, 02:44

Re: Run Alt AHK Version (RAAV) - Run AHK v2 scripts with one click

Post by boiler » 29 Jun 2020, 08:25

Thanks. I will incorporate most of those suggestions in the next update. I would have to investigate other file explorers. I imagine each one might need to be handled differently.

Post Reply

Return to “AutoHotkey v2 Scripts and Functions”