What script languages can be used with script rename?

Hello all DOpus users.
This is my first post although I'm old Amiga DOpus user. God bless DOpus for windows!

And now the question:
What script languages can be used with script rename? I really hate VBScript and I love Python. Can I use some Python script in DOpus (IronPython or ActivePython)?

In theory, any WSH (Windows Scripting Host) compatible scripting language can be used.

In reality, the only one we have found so far that works is VBScript, because it seems to be the only one that supports passing variables by reference.

If Python supports this then there's no reason I know of that it wouldn't work - try it!

(Please post general questions in Help & Support)

You can use any script language which works with the Active Scripting framework in Windows (which is most scripting languages) and which supports passing parameters by reference (which seems to rule out JavaScript).

There seem to be a couple of ways to make Python work with Active Scripting but it isn't clear which one is best and as far as I know nobody has tried it with Opus yet but it should work in theory unless Python doesn't support pass-by-reference.

mvps.org/scripting/languages/

@Jon

[quote]In reality, the only one we have found so far that works is VBScript, because it seems to be the only one that supports passing variables by reference.
[/quote]
@Nudel

[quote]You can use any script language which works with the Active Scripting framework in Windows (which is most scripting languages) and which supports passing parameters by reference (which seems to rule out JavaScript).
[/quote]

I've found out that PHP does in fact support passing arguments by reference.
In a function simply preceed the argument with a '&' character.
For the more Object oriented, there is more under Variants.

I can get the phpscript engine started, but I still have had no luck at all getting our rename function to work with PHP.
Perhaps I need to set something in the PHP.ini file or something .....
Well, someday maybe I'll have an inspired moment and it will all make sense.

Oh yes, I almost forgot, The default installation of Open Object Rexx includes ObjectRexxscript.
I can start the engine, but I don't understand the syntax of Open Object Rexx at all ( yet ).

[quote="Zippo"]
I can get the phpscript engine started, but I still have had no luck at all getting our rename function to work with PHP.[/quote]
How do you do that? PHP is installed on my system (I'm a web developer and use a WAMP system for developing and testing), but when I try to use it for scripting within DOpus, the message in the Script tab of the Output window says

It's the same with phpcli (and yes, both are in my path). So what do I have to enter as parameter for "@script"?

On the other hand I was able to create buttons that call PHP scripts that can rename files.

Such a button calls a PHP script with the file paths of the selected files as parameters like this:

phpcli C:\xampp\htdocs\php_cli\dopus\rename_to_txt.php -- {allfilepath$}

The script - here just an example script that adds '.txt' to the file name - looks like this:

[code]<?php
// get arguments
if (isset($_SERVER['argv']) AND is_array($_SERVER['argv'])) {
if (in_array('--', $_SERVER['argv'])) {
do {
$str_first_arr_element = array_shift($_SERVER['argv']);
} while ('--' != $str_first_arr_element);
}

// add '.txt' to the file name
foreach ($_SERVER['argv'] as $str_file_path) {
  $bool_check = rename($str_file_path, $str_file_path.'.txt');
  // you can react to renaming failure by evaluating $bool_check
}

}
?>[/code]
At the moment a DOS window is openened while the script is executed. I thought I read a posting here that dealt with this problem and showed a possible solution, but I can't find it anymore. Maybe it was another forum... :confused:

Greetings,
Jan

Ah, I found it again: [url]Renaming - #12 by JohnZeman]. You have to add

@runmode hide

to your button. :wink:

Greetings,
Jan

@script is only supposed to be used for rename scripts right now.

Also, phpcli looks like a command-line php runner which isn't related to Active Scripting. Active Scripting lets programs like Opus (and many others) run scripts in different languages without having to know about those languages.

Yes, I'm aware of that. :wink: That's what I tried, and I didn't find a way to choose PHP as scripting language. I don't know if there is one.

That's what I thought, too, but Zippo said "I can get the phpscript engine started". I wondered if this is really true (or if he just thought he had started it), and if so, how he achieved it.

On the other hand it may be interesting for him (and others) how to use PHP scripts for tasks like that - even if it's not perfect and there's no real integration, so I posted it.

Cheers,
Jan

Hi Enigma,

Thanks much for your PHP command Line scripting code.
Yes, I've also done some PHP Command Line scripting of buttons.

You need php5activescript.dll.
You then need to run at a DOS Admin Command Line:

regsvr32 php5activescript.dll

See activescript at PHP.net.

@script phpscript

[quote]Yes, I'm aware of that. That's what I tried, and I didn't find a way to choose PHP as scripting language. I don't know if there is one.
[/quote]
Yes, I knew you were aware of that.
I understand your post and code well.
I'm still thinking about this though and my free time is severely limited until Saturday.
Perhaps together we can solve this problem !

Gruss,
David
php5activescript.zip (18.5 KB)

Thanks for pushing me in the right direction. :slight_smile:

I hope so... :wink:

The php5activescript.dll was already on my system, I just hadn't registered it. Now the Hello World script from the PHP manual works, and the DOpus renaming script

@script phpscript function Rename_GetNewName($strFileName, $strFilePath, $fIsFolder, $strOldName, &$strNewName) { $strNewName = "test.txt"; }
at least leads to the following output in the Output window:

[quote]Successfully initialized 'phpscript' engine
Script started successfully[/quote]
But the script seems to crash or something like that - it doesn't do anything, and in the Output window the line

is missing. Even when the function is empty, the script won't "complete". When I try to use $WScript->echo() as in the example script from the PHP manual, DOpus crashes completely!

There's another strange thing: If I want to save it as a preset, the new name appears in the list. When I close the Rename window and open it again, the preset has gone... :confused: I had to create the preset file manually.

Well, since I didn't occupy myself with the Windows Script Host until now, I guess I have to learn quite a lot about it. Unfortunately the interplay of PHP and the WSH seems to be documented very poorly.

Cheers,
Jan

The WScript object won't exist for scripts running inside of Opus. If you want to send a string to the Opus Output Window (Script tab) you have to use something like this (in VBScript as I don't know the PHP syntax):

Dopus.OutputString "Hello World"

Of course, crashing is bad even if the script contains an error but it is likely that the cause of the crash is the PHP scripting engine rather than Opus itself since I doubt Opus knows about WScript or has any direct interaction with what the script does. I might be wrong but PHP is probably wrongly assuming that the WScript object will always exist which is only true if it's running under WScript.

The WScript object won't exist for scripts running inside of Opus. If you want to send a string to the Opus Output Window (Script tab) you have to use something like this (in VBScript as I don't know the PHP syntax):

Dopus.OutputString "Hello World"

I saw that in the manual and already tried to make something out of it. An object in PHP has a $ symbol before the name, and methods are separated from the object name by an arrow:

$Dopus->OutputString("Hello World");

should be the correct syntax. This way DOpus doesn't crash, but also nothing happens - there's no additional output in the Output window. But I'm not sure if the function code is executed at all - as I said, even an empty function doesn't lead to a completion of the script.

DOpus seems to crash whenever there's an error in the code. As I said, I don't know much about the WSH, but the assumption that the error lies there rather than on DOpus' side is probably correct.

Cheers,
Jan

[quote]The WScript object won't exist for scripts running inside of Opus. If you want to send a string to the Opus Output Window (Script tab) you have to use something like this (in VBScript as I don't know the PHP syntax):

Code:
Dopus.OutputString "Hello World"
[/quote]

Yes Nudel,
I have not yet found any method to send a string to the Opus Output Window using PHPscript.
Part of the problem is definitely syntax.
PHP does not understand Dopus.OutputString.
PHP also does not understand $Dopus.OutputString.
The '.' character has a different meaning in PHP.
It is a concatenation operator.
This is obviously different than the intent of Dopus.OutputString.

I have been able to write text files though.
Text files are the best I can do to output data from the rename script.

I know PHP sees an Object Dopus and an Object Rename, but I have not been able to reverse engineer any properties and methods.
PHP has such functions, although I understand them very little.
It is a wonderful technique to crash Dopus though.
The best result I've had are that the objects contain no properties or methods.

The above ActiveScript link to PHP.net documents the dll as :

You know this much better than I do,
but I can't help but think I'm doing something wrong, perhaps in the PHP.ini file.
At the very least, Enigma is finding the same results that I have found .
Well, so far anyway.

[quote="Zippo"]I have not yet found any method to send a string to the Opus Output Window using PHPscript.
Part of the problem is definitely syntax.[/quote]
Hm, this doesn't seem to be the problem - calling

$DOpus->OutputString('whatever');

works perfectly - if it is called from outside the function... :confused:

A call from inside the function is also possible if you explicitly add a function call.

As it seems, the PHP function isn't even called - which is what I suspected. But why? And what can I do about it? :wink:

Me too - but just from outside the function. What about you?

[quote="Zippo"]I know PHP sees an Object Dopus and an Object Rename, but I have not been able to reverse engineer any properties and methods.
PHP has such functions, although I understand them very little.[/quote]
These functions don't seem to work, which is not particularly astonishing, taking into account that those objects aren't "real" PHP objects.

Oh yes, it is... :wink:

Cheers,
Jan

I know nothing about PHP so this may be completely wrong but does PHP interpret an underscore in function names as something special, like to define a member function?

Zippo mentions that there's a Rename object of some sort in PHP (which I think he's found by listing all objects) and the function name is Rename_GetNewName so I wonder if that's turning into a GetNewName function on an object called Rename rather than a Rename_GetNewName function with global scope?

[quote="nudel"]I know nothing about PHP so this may be completely wrong but does PHP interpret an underscore in function names as something special, like to define a member function?

Zippo mentions that there's a Rename object of some sort in PHP (which I think he's found by listing all objects) and the function name is Rename_GetNewName so I wonder if that's turning into a GetNewName function on an object called Rename rather than a Rename_GetNewName function with global scope?[/quote]
It is a name convention to prefix member functions with an underscore, but that's it. Using the underscore in function names is absolutely normal; it's even the preferred notation since almost all of PHP's own functions have an underscore in their names.

You can see the two objects (or what PHP thinks are objects) for example when showing the contents of $GLOBALS:

ob_start(); print_r($GLOBALS); $str_output = ob_get_contents(); ob_end_clean(); $DOpus->OutputString($str_output);
A part of the output of this is

[code] [DOpus] => variant Object

[Rename] => variant Object[/code]

Greetings,
Jan

[code]@script phpscript

$type = variant_get_type($Rename);
$DOpus->OutputString($type);
$DOpus->OutputString("Hello World");[/code]

Outputs:

[quote]Successfully initialized 'phpscript' engine
Script started successfully
9
Hello World
[/quote]

The content type of the Variant Object Rename is 9.
It is an integer specifying a VT_XXX type.
I know it is NOT a string.
The PHP manual refers any questions as to what type the number 9 represents to the MSDN Library.
I couldn't find it there either.
Nudel, do you happen to know ?

Number 9, Number 9, Number 9, ......

9 is VT_DISPATCH - that is, an object derived from the IDispatch interface.

I've found something.

@script phpscript $type = variant_get_type($Rename); $DOpus->OutputString($type); $DOpus->OutputString(com_print_typeinfo($Rename,'GetNewName')); $DOpus->OutputString("Hello World");

Output:

[quote]Successfully initialized 'phpscript' engine
Script started successfully
9
True
Hello World
[/quote]

The real meat of this is the PHP function
bool com_print_typeinfo ( object $comobject [, string $dispinterface [, bool $wantsink]] ) .

[quote]The purpose of this function is to help generate a skeleton class for use as an event sink. You may also use it to generate a dump of any COM object, provided that it supports enough of the introspection interfaces, and that you know the name of the interface you want to display.

comobject should be either an instance of a COM object, or be the name of a typelibrary (which will be resolved according to the rules set out in com_load_typelib()). dispinterface is the name of an IDispatch descendant interface that you want to display. If wantsink is TRUE, the corresponding sink interface will be displayed instead.
[/quote]

If I substitute something random for the string 'GetNewName', the output is :

[quote]Script started successfully
9
Error at line 3, position 0
Unable to find typeinfo using the parameters supplied
False
Hello World
[/quote]

OK, I have some more here now.
Hopefully GPSoft won't go after me for hacking Directory Opus. :sunglasses:

@script phpscript $DOpus->OutputString(com_print_typeinfo($Rename,'GetNewName')); ob_start(); com_print_typeinfo($Rename,'GetNewName'); $typeInfo = ob_get_contents(); ob_end_clean(); $DOpus->OutputString($typeInfo); $DOpus->OutputString("Hello World");

Output:

[quote]Successfully initialized 'phpscript' engine
Script started successfully
True
class IDOpusScript_RenameEvent { /* GUID={CE3B9C86-CF4F-48B2-8D5A-44A82DC02733} /
/
DISPID=501 /
/
VT_HRESULT [25] /
function GetNewName(
/
VT_BSTR [8] [in] / $pszFileName,
/
VT_BSTR [8] [in] / $pszFullPath,
/
VT_I4 [3] [in] / $fIsFolder,
/
VT_BSTR [8] [in] / $pszOldName,
/
VT_PTR [26] [in][out] --> VT_VARIANT [12] */ &$varNewName
)
{
}
}

Hello World
[/quote]