v1tov2wrapper

Post your working scripts, libraries and tools.
sashaatx
Posts: 351
Joined: 27 May 2021, 08:27
Contact:

v1tov2wrapper

Post by sashaatx » 16 Apr 2023, 14:08

I've put together a fairly simple way to:
- Take an AHKv1 library
- using ahkv2converter, pass a script to be converted to v2 during runtime
- Example use cases for me were MagicBox, SmartGui, etc. On "Save" passing a script to be converted.

it's just got three snippets:
1. function to add to an old code, supplying a path or out-code
2. a launch script that handles pointing to the ahk.exe file
3. store temporary scripts or logs for runtime use.

Let's say I want AutoGUI's save function to convert the output script to v2
(step 0, download ahkconverter https://github.com/mmikeww/AHK-v2-script-converter)
This code launches the v1 library/gui/app

Code: Select all

#Requires Autohotkey v2.0
exe := "`"" A_ScriptDIr "\AutoHotKey Exe\AutoHotkeyV1.exe`" "
autogui := "`"" A_ScriptDIr "\AutoGUI.ahk`""
com := exe autogui
Run(com)
AutoGUI asks the user to select a path, then writes the v1 script to a path locally.
After completion I pass the path to my listener script.
This code goes inside "autogui.ahk" in this example:

Code: Select all

run_listener(FilePathToBeConverted){
    q := """"
    exe := q . A_ScriptDIr . "\AutoHotKey Exe\AutoHotkeyV2.exe" . q . " "
    script := q . A_ScriptDIr . "\listener.ahk" . q 
    com := exe . script
    Log := A_ScriptDir "\log.ahk"
    if FileExist(Log){
        FileDelete %Log%
    }
    FileAppend %FilePathToBeConverted%, %Log%
    
	    exe := "`"" A_ScriptDIr "\AutoHotKey Exe\AutoHotkeyV2.exe`""
	    convertahk := " `"" A_ScriptDIr "\v2converter.ahk`" "
 	   command := exe convertahk "`"" FilePathToBeConverted"`""
 	   Run(command)
	}
}
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

Return to “Scripts and Functions (v2)”