Visual Basic Script support in AutoHotKey
VBScript support would allow AutoHotKey executables to do more with less need for supporting files or other external scripts and give them greater functionality.
I just put down a little visual of what I mean, but of course however it would be done, it would be very useful.
VBS_START ("Inputbox", add whatever)
response = inputbox("Type anything in the box and click OK.", "Input box demo")
if response <> "" then
msgbox "You typed " & response & ".", 64, "Your Input"
VBS_RUN ("Inputbox", "cscript")
VBS_START and VBS_END could kind of be like #include, but are inside of the script as oppose to calling another script externally.
VBS_RUN could be a modified version of a command like RunWait('cscript.exe "c:\long file\name\script.vbs"') But where RunWait was was getting the VBS script externally, VBS_RUN would use what is between VBS_START and VBS_END and could send that to cscript.exe or wscript.
Of course if some other way was found for AutoHotKey to compile VBS than that would be even better.
EDIT- installs VBScript help doc in .CHM format (might be useful at some future point)
Visual Basic for Applications free tutor
http://www.users.big... ... .htm#Part1
That's good. I'll see if this can be done for a future release, perhaps by learning from the source of MediaBasic or finding some info on MSDN about how to integrate VBS.
There is also a freeware program, which in various ways is less advanced but in others more, called MediaBasic ( http://www.uolang.org/mediabasic/ ) that can directly compile .vbs files into .exe.
As always, development help is welcome from anyone, whether it be in the form of finding source code (as you did), contributing code, or finding technical articles that explain how to program specific things such as integrated VBS support.
I think that, rather than just vbs, if you used activescript instead, thus enabling the use of vbs, jscript, perlscript, rubyscript, or whatever. Unfortunately, my knowledge of how to set this up is limited to VB .
Related to that... I found these interesting...
http://msdn.microsof... ... d=28001169 (Microsoft Active scripting info.)
http://activescript.....com/index.html ( ActiveScript for Delphi )
http://www.geocities... ... /main.html (ActiveScriptRuby)
Also... for MediaBasic ( http://www.uolang.org/mediabasic/ ) you have to copy the contents of a/your VBScript into their IDE and then compile it. MediaBasic understands the VBScript language syntax.
info from http://www.microsoft... ... iptit.mspx
ScriptIt does not have many of the sophisticated features of traditional scripting languages such as Microsoft Visual Basic, Scripting Edition, Microsoft Jscript™ development software, or Perl. However, the mkfile line allows you to enhance and extend ScriptIt's capabilities with the features of these other scripting languages. The mkfile line capability allows ScriptIt to write a Visual Basic, Scripting Edition, Jscript, Perl script, and so forth, at run time. The external script can then be executed using a ScriptIt run or runwait line, or it can be executed from a title line using the left quotation mark (`) directive as described earlier. This will result in the standard output of the external script being redirected to the designated window title. Note that when you use any of the supported Windows Script Host languages from within the context of a title line, you should use CScript.exe, not WScript.exe, to launch them. ScriptIt expects that any command launched from a title line will send its output to standard output. WScript.exe does not use standard output.
The parameters are as follows.
This parameter specifies the file name that is to be created or appended. Environment variables such as %Temp% can appear in the filename string.
This parameter specifies the line that is to be written or appended to filename. This line could be Visual Basic, Scripting Edition code, Jscript code, Perl code, and so forth. Or it could just be normal text that you want to save in a file.
If you want to create a multiple-line file, you need to include multiple mkfile lines in your script, each with the same filename.ext. The first instance of a given filename.ext opens a new file. All subsequent mkfile lines with the same filename.ext append lines to that file. Once you have finished building your new external script file, a ScriptIt run or runwait line can execute it. As indicated earlier, you can also redirect your external script's output to a specific window by using a ScriptIt title line with a keystroke segment that begins with the left quotation mark (`) followed by the command-line necessary to run the external script. For example, the following uses a run line to launch an instance of Notepad:
mkfile %tmp%\t.vbs=set wshshell=wscript.createobject("wscript.shell")
mkfile %tmp%\t.vbs=set wshnetwork=wscript.createobject("wscript.network")
mkfile %tmp%\t.vbs=wscript.echo wshnetwork.username
Untitled - Notepad=`cscript //nologo %tmp%\t.vbs
run=`if exist %tmp%\t.vbs del %tmp%\t.vbs
It then uses mkfile lines to build a three-line Visual Basic, Scripting Edition file named %tmp%\t.vbs, and then uses a title line and a command line preceded by a left quotation mark (') to run t.vbs, redirecting the output to the Notepad window. Finally, the ScriptIt script cleans up after itself by using a run line with a left quotation mark to delete %tmp%\t.vbs.
You can download this old grandfather of AutoHotkey and Autoit at - http://www.csst-tech... ... 20Utility/
I really hope a way can be found to include this type of functionality.
For example, my most frequent use of this is to get Regular Expressions (something else on your wishlist). I just use VBScript's regular expressions and life is good. You can also use Active Scripting to fire up VBScript or JScript itself, although I very rarely do this.
If you could do something like they did with Active-X support, a lot or your wish-list items would go away immediately.
If you look at Macro Scheduler (Shareware) it follows the same route (as it allows to include/implement VBS within its native code) That would be of help for all of those who are familiar with such a "second" language.
On the other hand, AHK's benefit (like it was with AutoIt2) is its simplicity.
If it comes to complex tasks it's worth to think about to find the right hammer/tool for a specific nail/issue, as IMHO its legitimate to use an ATV instead of a Ferarri if you've to cross a muddy acre (if available :wink:).
Man, you should definitely have a look at Perl(/Tk) or Tcl/Tc or ...
my most frequent use of this is to get Regular Expressions (something else on your wishlist).
Last but not least (I guess Chris would recommand this too: AutoIt2/3 offers an Active X module (?), maybe it could be used with AHK as well (???))
Thanks for mentioning it and describing it so nicely. I'm definitely going to research this to find out how difficult it is to include.
You can use syntax similar to Visual Basic's CreateObject to open any active-x control. This very nicely solves a lot of problems.
AutoHotkey, by virtue of FileAppend has activex/com/ole (in a way) because it can simply FileAppend VBScript code to a text file and execute it.
You can even use this for .NET languages like cscript (C# script) and various .NET scripting programs.
Example using VBScript, fso, CreateObject, etc....
FileAppend, ( Dim fso, f, ftext, r, stext, lstart, i, ls, fok Set fso = CreateObject("Scripting.FileSystemObject") on error resume next ftext = inputbox("Enter the path of the file for processing.", "FILENAME") if ftext = "" then set fso = Nothing 'WScript.Echo fco wscript.quit end if '--check whether the path is valid: If fso.fileexists(ftext) = false then fok = false do while fok = false r = msgbox("The path is wrong, there's no such file. Do you want to re-enter?", 36, "Woops!") if r = 7 then set fso = nothing wscript.quit else ftext = inputbox("Enter the filename for processing.", "FILENAME") if fso.fileexists(ftext) = true then fok = true exit do end if end if loop end if fs = inputbox("What is the string you're looking for? This will tell you the number of occurences.", "Enter string to find") if fs = "" then set fso = nothing wscript.quit end if '--open the file and read it into the variable stext: set f = fso.opentextfile(ftext) stext = f.readall f.close set f = nothing set fso = nothing '--more instances of the string. lstart = 1 i = 0 ls = 1 do until ls = 0 ls = instr(lstart, stext, fs, 1) If ls <> 0 then i = i + 1 lstart = ls + 1 end if loop msgbox i ), c:\testbox.vbs Runwait,c:\testbox.vbs
I think this aspect of AutoHotkey should be emphasized. Why?
1. In many situations, this type of ability is the equal of AutoitX.dll or its built-in Activex/OLE/COM.
Programmers from other other languages can use their favorite code inside of AutoHotkey for various problems that they encounter.
2. AutoIt's AcitveX is a copy of VBScript. So why not use the real thing?
Even better, you can use more than just VBScript or Jscript.
3. Many AutoHotkey programmers don't have to wait for certain type of increased functionality in AutoHotkey, because while waiting they can use any scripting language that can use wscript or cscript, like Jscript , VBscript, or Perl. They can also use various .NET scripting languages that use VB.NET or C# script ( http://www.codeproje...ript_for_CP.asp ).
I was wondering if "FileAppend", "Run", and/or "RunWait" could be enhanced a bit more or a similar command created that specifically deals with handling other scripting languages and .NET??
A big enhancement would be to see if you could pass the commands to wscript or cscript without a temp file or .dll (like cmdret (great program)). I know its been talked about, but that would make this kind of feature even better.
I think the target language's interpreter would have to have built-in support for reading the commands from stdin. Does anyone know if VBScript or the others support this?
...if you could pass the commands to wscript or cscript without a temp file of .dll (like cmdret (great program)).
One problem with using FileAppend is that the script to be executed won't have access to any AutoHotkey variables, though I imagine you could pass parameters in via the command line. Another question is how to get data back out, which could be done via the exit code (for a single integer) or by having the external script write to stdout or a file.
I seem to remember that some macro languages allow seamless integration of VBScript so that both languages can see each other's data.
Thanks for the ideas.
OtherScript, , (maybe some other commands),
Whatever the scripting language
), (maybe send to "Clipboard" and/or "tmp" file), cscript.exe (whatever .exe used to run other script).
Note: Perhaps you could have the contents of the clipboard piped to cscript, wscript, etc...
c:\testbox.vbs > c:\windows\system32\cscript.exe
That works, so why not from the clipboard?
Anyway, these type of commands allow Autohotkey to do whatever else you need to do too. Even if that was ActiveX/COM/OLE, .NET, something in Perl, compiling a .NET DLL, etc.. it would not matter.
AutoHotkey advantage over the others will be its simplicity and/or automation abilities. Nevertheless, as AutoHotkey develops, there may be something people want from another scripting language. AutoHotkey could provide the "best of BOTH worlds", so that people can do whatever they need to