WScript Object not accessible ?

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
amix
Posts: 49
Joined: Wed Aug 22, 2007 1:26 pm

WScript Object not accessible ?

Post by amix »

I checked "Clarification Running a script two ways" and according to it, I can not access the Zeus object from the WSH. (But I could use the DDE interface of Zeus for external control, according to the Zeus docs).

What I wanted to do tonight was to call the WScript.Shell object from within a Zeus macro and I thought, this should work, since it is the other way around. Instead I got a dialog, that told me, that the scripting engine has found a problem, that this is, most likley, not a bug in Zeus but may be one in the scripting DLL.

Here is the zeus.debug() output:

Code: Select all

Debug: Debug: Macro trace debugging is active.
Debug: GetIDsOfNames call succeeded.
Debug: screen_update_disable
Debug: GetIDsOfNames call succeeded.
Debug: macro_tag
Debug: GetIDsOfNames call succeeded.
Debug: is_document
Debug: GetIDsOfNames call succeeded.
Debug: is_marked
Debug: GetIDsOfNames call succeeded.
Debug: MarkCopy
Debug: GetIDsOfNames call succeeded.
Debug: MarkHide
Debug: GetIDsOfNames call succeeded.
Debug: get_clipboard_text
Scripting Error :>  File: E:\zfw\zScript\run-in-IE.js (29:2) >>
Reason: 'WScript' ist undefiniert
Debug: Script object destroyed.
Macro script generated '17' Debug, Error and/or Warning message(s).
"d:\work\zeus3.96\apollo\zfwhlp01.cpp" (337)    Unexpected error opening the 'E:\zfw\zHelp\yuiapi.zix' information file.
Interestingley, it also moans about the index file for the YUI API docs missing, which is true. I don't know why it is missing, however. Seems unrelated, though and I recreated it....yes, I re-did the macro-execution and the YUIaoi.zix is still there and nothing got reported. So this was by accident, I guess.
Oh, and here is the (unfinished) script I am having the problem with:

Code: Select all

// Name: 		run-in-IE.js
// Host: 		Zeus for Windows
// Purpose:	Utility for WindowsScript development. Takes the active
//					document (or a marked area), wraps it into HTML and executes
//					it on the IExplorer scripting host.
// TODO:		Add argument parsing, document-type recognition, user-input,
//					special HTA routines (maybe defined in a project specific
//					configuration). Error-Checking.

function key_macro() {
	zeus.debug_enable();															// report to Zeus Debugger
	debugger;																					// should open Windows Script Debugger, does not. May need WSH object.
	zeus.screen_update_disable();											// lock Zeus

	fname = zeus.macro_tag('$FileName');

	if (zeus.is_document() == 1) {
 		if (zeus.is_marked() == 0) {										// if document has no mark set
			zeus.MarkSelectAll();													// mark it all
			zeus.MarkCopy();															// copy to clipboard
			zeus.MarkHide();															// release mark
			buf = zeus.get_clipboard_text();							// and paste that into a buffer
		};
		else {
			// if document has mark set, use this
			zeus.MarkCopy();
			zeus.MarkHide();
			buf = zeus.get_clipboard_text();
		};
	};

		var wsh = new ActiveXObject('WScript.Shell');									// create a WSH
		var fso = new ActiveXObject('Scripting.FileSystemObject');		// and a FileSystem Object

		// TODO:
		// parse args, they contain the filetype we are currently working
		// with. If JS we call makeHTML() and pass it to IE, if HTA we
		// pass it directly to HTA.exe
		oArgs = WScript.Arguments;

		// construct TempFile name
		var uenv = wsh.Environment('USER');
		var TmpFile = fso.BuildPath(uenv('TEMP'), 'zfwtmp.html');

		var oTmpFile = fso.CreateTextFile(tmpfile, True);							// open TempFile for write
		makeHTML('js',buf);																						// call our utility function

		// TODO: Error checking

		// Run our TempFile in IExplorer
		zeus.system("iexplore.exe " + TmpFile, zeus.macro_tag('$FileDir'), 1, "Running in Internet Explorer...");

	// preliminary HTML creation routine
	// TODO: Error-Checking
	function makeHTML(lang_type, editor_text) {
		oTmpFile.WriteLine('<html>');
		oTmpFile.WriteLine('<head>');
		oTmpFile.WriteLine('<title>Testing...</title>');
		if (lang_type == 'js') {
			oTmpFile.WriteLine('<script language=\"Javascript\">');
			oTmpFile.Write(editor_text);
			oTmpFile.WriteLine('</script>');
		};
		oTmpFile.WriteLine('</head>');
		oTmpFile.WriteLine('<body>');
		oTmpFile.WriteLine('</body>');
		oTmpFile.WriteLine('</html>');
	};

	// release Zeus
	zeus.screen_update_enable();
	zeus.screen_update();
};

// run macro
key_macro();
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

I can not access the Zeus object from the WSH.
That is correct.

There is no such thing as a Zeus scripting object.

Zeus does not expose any sort of COM/ActiveX object interface.
Here is the zeus.debug() output:Code:
Scripting Error :> File: E:\zfw\zScript\run-in-IE.js (29:2) >>
Reason: 'WScript' ist undefiniert
The reason the script does not run is there is no 'WScript' object defined.

This object is provided by the csript.exe and wscript.exe WSH's, but Zeus does implement this object.

For example, consider this test.js script file

Code: Select all

function key_macro()
{
    WScript.Echo('Echo Testing');

    var wsh = new ActiveXObject('WScript.Shell');                           // create a WSH
    var fso = new ActiveXObject('Scripting.FileSystemObject');      // and a FileSystem Object

    // construct TempFile name
    var uenv = wsh.Environment('USER');
    var TmpFile = fso.BuildPath(uenv('TEMP'), 'zfwtmp.html');

    wsh.Popup('Temp File Name is: ' + TmpFile);
};

// run macro
key_macro();
If you run this via the command line as follows:

Code: Select all

cscript.exe test.js 
you will get Echo Testing sent to the console window output and then you will see the popup window.

If you run this via the command line as follows:

Code: Select all

wscript.exe test.js 
you will now get Echo Testing as a popup window followed by the second popup window.

If you try to run this macro in Zeus you will get this error message:

Code: Select all

Scripting Error :>  File: d:\temp\test.js (3:4) >>
Reason: 'WScript' is undefined
Macro script generated '1' Debug, Error and/or Warning message(s).
and the error relates to the fact that Zeus does not implement the 'WScript' object.

Do you need the 'WScript' object :?:

In your script you have this code:
// TODO:
// parse args, they contain the filetype we are currently working
// with. If JS we call makeHTML() and pass it to IE, if HTA we
// pass it directly to HTA.exe
oArgs = WScript.Arguments;
But I don't see any references to the oArgs variable.

Cheers Jussi
amix
Posts: 49
Joined: Wed Aug 22, 2007 1:26 pm

Post by amix »

jussij wrote:This object is provided by the csript.exe and wscript.exe WSH's, but Zeus does implement this object.
I see. Why don't you just give access to the whole Windows Scripting subsystem ? I am not aware, what this needs on the side of an application programmer (ie: how the ActiveScript gets implemented) but it seems nifty to give the user this freedom.

A little background:
I grew up on AmigaOS, used it exclusively till 2001. It had no generic scripting host, but a REXX derivate (ARexx) was the system's default scripting language, starting the ARexx interpreter as background process upon boot. The programmers needed to link to a shared library (rexxsyslib.library) and could then implement their own command-set, which would expand the ARexx language by the host's functions and instructions. In the end every major application and even many Freeware projects would offer an ARexx host, that simply could use any part of that language. My favorite text-editorr (Golded) was pretty similare in certain regards to Zeus. Everything was a command, internally, that could be used from scripts, configured to the keyboard, the mouse or toolbars. That means, it was completley configurable in any part. Such a technology is ideal. By the time I had implemented primitive ASCII painting routines (boxes, circles, lines), configured to toolbars, so I could do some diagrams for UseNet messages. Also it was very nice to build a little IDE by the use of scripts and external commands/applications (GoldED had scriptable UI parts, like a listview and a dynamic quick-help view). One could define the menus as one wanted defining bool values to on/off states and then set certain aspects, query these from scripts and execute the script with different values then. The filemanager I used was just the same. Having written a script, that would parse in and display my message-database I could display emails as archives, within folders on the filesystem (of course, this was only pseudo virtual, one simply could fll the listers of the filemanager with any string-values and control it all by scripts). At the end of my time on AmigaOS I would use applications just as I'd shared function libraries, remote-controlling repetitive tasks (/mail list new, /mail dump MsgNum, /mail reply MsgNum from the IRC client, instead of starting the MUA, for example).

Okay, this was a little off-topic excursion, I just wanted to show, what a scripting-host, that is open into every direction is capable off.
Do you need the 'WScript' object :?:
I believe so, yes, since I want to add different configuration-files later. The script is for an ActiveScript development environment. I want to use IExplorer as host, since I got DebugBar installed, which is a DOM viewer and JScript debugger. I want to grab the text from Zeus, wrap it into a DOM and pass it to IE, where it gets tested/debugged. It may be HTA, it may be more simple, it may be HTA with certain HT-Application elements set and so on.


In your script you have this code:
// TODO:
// parse args, they contain the filetype we are currently working
// with. If JS we call makeHTML() and pass it to IE, if HTA we
// pass it directly to HTA.exe
oArgs = WScript.Arguments;
But I don't see any references to the oArgs variable.
That is a TODO. Of course I won't need it, if I can pass arguments to the ActiveScript macro via Zeus. I want to use it later to configure the script run-time. Also the arguments-parsing may become interesting when trying to access the rest of the system from Zeus, via the (limited) WScirpt Object or the Scripting.* Objects or any other COMponent.

Is the WScript Object the only non-IE (ie 'document') ActiveScripting object not available via Zeus ?
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

I see. Why don't you just give access to the whole Windows Scripting subsystem ?
The difficulty is that Zeus scripting languages like Lua and Python are not based on ActiveScript.

Also as far I can tell the 'WScript' object does not provide anything that can not already be done by one of the Zeus built-in macro functions:

http://msdn2.microsoft.com/en-us/library/2795740w.aspx

And there are things that don't really make sense. For example what should WScript.Echo("Some text") do :?:

Should it write to the currently active document, display a popup message, write to the debug window etc :?:
My favorite text-editorr (Golded) was pretty similare in certain regards to Zeus. Everything was a command, internally, that could be used from scripts, configured to the keyboard, the mouse or toolbars. That means, it was completley configurable in any part.
That sounds like a very nice editor :)
I just wanted to show, what a scripting-host, that is open into every direction is capable off.

Because the scripting feature came late to Zeus it is definitely not as flexible as it should be :(

If I had the time again I think I would adopt a similar approach where by the scripting engine is the foundation for the editor, rather than just a bolt on as it currently is.

With the scripting engine at the core of the editor suddenly everything becomes completley configurable which is very nice indeed :)
The script is for an ActiveScript development environment.
While the ActiveScript framework is very nice indeed, unfortunately it was not around when scripting was first added to Zeus :(

The histroy of Zeus scripting started out with the home grown C Script, followed by Lua Script, then Python Script and finally all the Active Script languages. Because of this heritage the scripting in Zeus is totally different than if it had been based purely on ActiveScript.

It is exactly because of this heritage that Zeus manages to do ActiveScript, yet it still gets away with not having to implement a sort of Zeus COM object :)

Once again when Zeus first had scripting COM did not exist ;)
That is a TODO. Of course I won't need it, if I can pass arguments to the ActiveScript macro via Zeus.
Ok, I understand. You have pointed out one thing that WScript implements that Zeus does not currently provide :oops:

I'll take a look at how hard it would be to allowing arguments to be passed to Zeus scripts.

Is there anything else in WScript that is missing from the Zeus scripting :?:
Is the WScript Object the only non-IE (ie 'document') ActiveScripting object not available via Zeus?

I'm not really sure. I only have a limited knowledge of the ActiveScripting framework. But I would have though nearly everything is available, since you should be able to create and use COM objects within the Zeus ActiveScript.

Cheers Jussi
amix
Posts: 49
Joined: Wed Aug 22, 2007 1:26 pm

Post by amix »

jussij wrote:The difficulty is that Zeus scripting languages like Lua and Python are not based on ActiveScript.
I understand.
And there are things that don't really make sense. For example what should WScript.Echo("Some text") do :?:
Good question. It may be interesting in some macros, as status output to the Zeus console, but, of course, this is just a play of thoughts. The WScript Object has a lot of stuff, that is not very attractive for non-admins, but the args-parsing is pretty important by times.
That sounds like a very nice editor :)
True. It also had a binary extension API, mixed syntax hiliters (they all were grammar-based) were also possible (ie: Javascript+HTML+CSS or LaTeX with integrated spell-checking, but only the contents portion, etc.) and support for AmigaOS's AutodDoc/XRef system (which in itself was extremly useful and, even if late 80ies and early 90ies up to today's standards). That means, it would display the function description, show the matching definition from the includes, realtime in a little pane, while cursor over.
Zeus is very similare in many regards and that is why I like it.
In the meanwhile it has become a little bit more than just an editor Dietmar Eilert (the author) calls it CubicIDE.
If I had the time again I think I would adopt a similar approach where by the scripting engine is the foundation for the editor, rather than just a bolt on as it currently is.
Send me a mail, when you do it, I'm sure I would have some feature-requests ;-))) No, seriously, I would make the editor-part itself an extremley sophisticated and very abstract text-parsing engine, giving chance to things not seen before (except with emacs, maybe) and I would frame or stack this editor with the scripting, which would give all functionality to that editor part and the rest.
With the scripting engine at the core of the editor suddenly everything becomes completley configurable which is very nice indeed :)
Absolutley ! :-) Zeus is already very nice indeed. It does it like Golded: based on document-types and is as focussed.
I'll take a look at how hard it would be to allowing arguments to be passed to Zeus scripts.
That would be nice, indeed, as long as it is not too much of a burden. I guess Zeus is stuffed up to its limits.
Is there anything else in WScript that is missing from the Zeus scripting :?:
Not, that I'd know of any.

Hmmm...I did find functionality to query and set the search and replace strings, but I did not find the find/replace functions ?!
(I want to calculate a clsid with uuidgen.exe and insert the result into the template upon load)
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hmmm...I did find functionality to query and set the search and replace strings, but I did not find the find/replace functions ?!
(I want to calculate a clsid with uuidgen.exe and insert the result into the template upon load)
Just use the SearchNext, SearchPrevious, ReplaceNext, ReplacePrevious keyboard functions ;)

For example:

Code: Select all

function key_macro()
    local text
    text = user_input("Enter Find Text", "", "Zeus Find")
    set_find_text(text)
    SearchNext()
end

key_macro() -- run the macro
Cheers Jussi
amix
Posts: 49
Joined: Wed Aug 22, 2007 1:26 pm

Post by amix »

Will do so, thanks :-)
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

The latest Zeus release allows arguments to be passed to macros.

These arguments can be accessed from within the macro using the argc and argv macro functions which are described in the online help.

NOTE: Arguments are passed to the macro using the Arguments text entry field found in the Macros, Options menu dialog.

The latest Zeus patch can be found here: http://www.zeusedit.com/forum/viewforum.php?f=6

Cheers Jussi
Last edited by jussij on Thu Oct 09, 2008 3:47 am, edited 2 times in total.
amix
Posts: 49
Joined: Wed Aug 22, 2007 1:26 pm

Post by amix »

Very nice, thank you.
Post Reply