The main purpose of this tiny script is to run on-the-fly the AHK code posted in this forum simlpy selecting the code and pressing the appropriate hotkey.
Obviously it will produce some results only for the code that it does. I mean if the highlighted code is a function without any call to it it will produce nothing. It doesn't neither make any syntax check.
Could be enhanced by presenting the grabbed code in an Edit box giving the user a way to modify it and run it by pressing a button but this is not my goal.
It's only a really basic way to test the code, whenever possible, and ( as I do a lot of times ) once tested, leave the user to decide to saving it in some location for future use. Nothing more.
I hope can be useful for someone.
Code:
#SingleInstance force
#Persistent
SetWorkingDir %A_ScriptDir%
#b::
fnam = %A_ScriptDir%\%a_now%.ahk
oldClipboard := ClipboardAll
send ^c
ClipWait, 1
FileDelete,%fnam%
code := clipboard "`r`nOnexit, DeleteTemp`r`nDeleteTemp:`r`nFileDelete, " fnam "`r`nExitApp`r`n`r`nreturn`r`n"
FileAppend, %code%, %fnam%
Run, %fnam%
Clipboard := oldClipboard
return
P.S: The code will be saved in a temporary file that will be deleted by exiting the running script, so nothing will change in your script folder.
Regards