Jump to content

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

AHK_L<>AHKBasic Switcher


  • Please log in to reply
17 replies to this topic
0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011
Switch between AHK_L and AHKBasic.

HOW IT WORKS:
Install AHK_L or AHKBasic to a separate Program Files directory so you have 2 versions on 1 system.
The other version MUST BE INSTALLED IN PROGRAM FILES!
When you run the script, it will replace one version with the other.

No longer touches the AHK's executable.
#SingleInstance ignore

RegRead, poVal, HKCR, \AutoHotkeyScript\Shell\Open\Command
If !poVal {
  MsgBox, 0x10, Error!, Cannot find AutoHotkey.exe`nThis script will now exit.
  ExitApp
}

MsgBox, 0x4, AHK Switcher, % "You are running AHK " (v:=A_AhkVersion) "`n"
			. "Switch to AHK_" ( shNm := ( InStr( v, "1.1." ) ? "Basic" : "L" ) ) "?"
IfMsgbox No
  ExitApp

RegExMatch( A_AhkPath, "\\\K\w+\.\w+", aNme )
Loop, % A_ProgramFiles "\*.*", 0, 1
  If RegExMatch( A_LoopFileFullPath, aNme ) {
    FileGetVersion, aVer, % swDir := A_LoopFileFullPath
      If ( RegExReplace( aVer, 0 ) <> RegExReplace( A_AhkVersion, 0 ) ) {
        swDir := """" RegExReplace( swDir, ".*\\\K.*" ), fnd:=!fnd
        Break
      }
  }

If !fnd {
  Msgbox, 0x30, Switch Stopped!, % "AutoHotKey " A_AhkVersion " was the only version found!`n"
			. "Please install AHK_" shNm " in a separate Program Files Directory."
  ExitApp
}

cmp = Compiler\Ahk2Exe.exe`" /in `"`%l`"
cmpVal := swDir . cmp
opnVal := swDir . aNme """ "`"`%1`"" `%*" 

Loop 2
  RegWrite, REG_SZ, HKCR, % "AutoHotkeyScript\Shell\" ( (i:=!i) ? "Compile" : "Open" ) "\Command",, % ( i ? cmpVal : opnVal )

TrayTip, Versions Switched!, % "Successfully switched to AHK_" shNm "!",, 1
WinWaitClose, ahk_class tooltips_class32
ExitApp
I've tested this successfully on WIN764/32 and XP32.

It can take long find the switch version if only 1 instance of AHK is installed.
This is because it searches the Program Files folder recursively.
To address this, I may add a search display with a cancel button.

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011
Another possible issue could be the context compiler command.
Especially, but not limited to,
Unicode and ANSI compiler versions and different also bit versions.

Looking into this..

nimda
  • Members
  • 4368 posts
  • Last active: Jan 15 2014 02:47 PM
  • Joined: 26 Dec 2010
Just a note: there are zip files available for AHK Basic and AHK_L, so sandboxie isn't needed.

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011
thnx nimda that actually relieves some concerns I had ( fe. Registry installs etc ).
I found the basic zip not luck finding the _L zip though.
Any clues as to a safe location?

Is this valid?
<!-- m -->http://www.autohotke... ... key_Lw.zip<!-- m -->

edit: its ok I found the 3 versions on the _L page :)..

ty agn

So it also looks like alls I need to do is switch the compiler too and it should be pretty much ok ( other than compatibility issues ).

Lexikos
  • Administrators
  • 9442 posts
  • Last active:
  • Joined: 17 Oct 2006
Rather than swapping the files around, it would be more appropriate to swap the file associations, which would include all context menu items. If you copy and rename the "AutoHotkeyScript" key under HKCR, you can change the default value of the ".ahk" key to point to whichever one you want. (Install one version, rename the "AutoHotkeyScript" key, then install the other version.)

noname
  • Members
  • 412 posts
  • Last active:
  • Joined: 12 Nov 2011
For testing both versions i use different extensions using Majkinetor tool:

<!-- m -->http://www.autohotke...topic54134.html<!-- m -->

You only have to change ahk into ahkl and the file would be executed with the other version.
For me it has the advantage that i can use PSPad highlighting and syntax linked to the extension so i get a visual indication if i open a file for editing.

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011
@Lexikos
Switching association was my 1st thought.
I was just unsure how to get around one version overwriting the previous key @ install ( hence extraction ).
I'm looking at the HKEY_CLASSES_ROOT key for .ahk and I don't see a key pointing to an exe, only Template.ahk
( which is a non existing file, yea I searched it ;) ). BTW I'm using Win7Ult 64bit.
Also how would I automatically determine the location of the 2nd install version??

Thanks again for your insight.

@yui
Will look into this ty.

Lexikos
  • Administrators
  • 9442 posts
  • Last active:
  • Joined: 17 Oct 2006

I'm looking at the HKEY_CLASSES_ROOT key for .ahk and I don't see a key pointing to an exe,

As I said, the default value of the ".ahk" key identifies another key. You can also retrieve or set this value at a command prompt using the assoc command. For example,
C:\>assoc .ahk
.ahk=[color=red]AutoHotkeyScript[/color]

Also how would I automatically determine the location of the 2nd install version??

Chronologically, only the path of the second installed version is kept in the registry, since it overwrites the first one (unless you rename the HKLM\Software\AutoHotkey key).

You only have to change ahk into ahkl and the file would be executed with the other version.

That script associates .ahk with "AutoHotKey" and .ahkl with "AutoHotKey_L" in the same way that the default installer associates .ahk with AutoHotkeyScript. My suggestion was basically to swap the association of .ahk between AutoHotKey and AutoHotKey_L. I suggested modifying the registry, but it can also be done with the assoc command as in majkinetor's batch script.

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011

C:\>assoc .ahk
.ahk=[color=red]AutoHotkeyScript[/color]

Very good to know!
That way the packages need not be touched directly and scripts are executed accordingly :mrgreen:
Much appreciated!

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011

Rather than swapping the files around, it would be more appropriate to swap the file associations, which would include all context menu items. If you copy and rename the "AutoHotkeyScript" key under HKCR, you can change the default value of the ".ahk" key to point to whichever one you want. (Install one version, rename the "AutoHotkeyScript" key, then install the other version.)

I'm glad you wrote this as I updated another system with the latest _L version only to find my script pointing to the above mentioned key.
I'm going to have to update this now for sure.

Thanks again hope all is well with you and the project is still coming along.

dra
  • Members
  • 100 posts
  • Last active: Jan 11 2013 08:03 PM
  • Joined: 11 Dec 2011
I have installed AHK_B in a folder called AHK and wrote scripts using it which are stored them in the same folder. Learning that I needed to use COM in some scripts, I then installed AHK_L in a separate folder but lost all the file associations of my scripts written with AHK_B. I'm not a programmer and don't understand the above discussion very well. I'd really appreciate a simple step by step recipe on what I need to do to be able to switch between these versions and not have problems.

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011
I still have to update this,
please stand by..........

sumon
  • Moderators
  • 1314 posts
  • Last active: Jul 06 2014 06:26 PM
  • Joined: 18 May 2010

I have installed AHK_B in a folder called AHK and wrote scripts using it which are stored them in the same folder. Learning that I needed to use COM in some scripts, I then installed AHK_L in a separate folder but lost all the file associations of my scripts written with AHK_B. I'm not a programmer and don't understand the above discussion very well. I'd really appreciate a simple step by step recipe on what I need to do to be able to switch between these versions and not have problems.


The easiest solution is to use AHK_L only, since 98% of all scripts are compatible with _L. Version switching is an 'advanced' hack which most users will not need to do. If you get a problem, read the error message and adjust your code, or ask for help on the forums.

dra
  • Members
  • 100 posts
  • Last active: Jan 11 2013 08:03 PM
  • Joined: 11 Dec 2011

The easiest solution is to use AHK_L only, since 98% of all scripts are compatible with _L. Version switching is an 'advanced' hack which most users will not need to do. If you get a problem, read the error message and adjust your code, or ask for help on the forums.



Seems simple enough. So if I stick with just AHK_L, then how do I fix the file association problem I am currently having with my existing AHK_B scripts? Thanks for your help.

sumon
  • Moderators
  • 1314 posts
  • Last active: Jul 06 2014 06:26 PM
  • Joined: 18 May 2010

The easiest solution is to use AHK_L only, since 98% of all scripts are compatible with _L. Version switching is an 'advanced' hack which most users will not need to do. If you get a problem, read the error message and adjust your code, or ask for help on the forums.



Seems simple enough. So if I stick with just AHK_L, then how do I fix the file association problem I am currently having with my existing AHK_B scripts? Thanks for your help.


If your scripts are already associated to AHK(_L) you should experience no problem. Otherwise, try running the latest _L installer again, or right-click a script, "Open with..." and select "Always use this program [...]", selecting _L.

There is no difference in file extension or type between _L and Basic scripts. The only difference is that scripts with a later version & _L syntax may not run with an old (Basic) version of AutoHotkey. If you only use your own scripts, version doesn't matter (though _L might be handy for f.ex COM, better Gui handling, or arrays) - if you also want to use others' scripts, _L is required since it covers compatility for both modern (_L) scripts and scripts written in Basic.

There are of course some exceptions, but those are rather rare.

Aforementioned reasons is why many forum members 'Recommend' AHK_L to both beginners and advanced users. For more info, see "Why?" in my signature.