How to use Perl or JScript?

Hello,

I've seen that DOpus shows a default VBScript for renaming.

How can I use Perl or JScript for renaming?

Are there examples of scripts (VBScript, Perl, JScript or whatever)?

Thank you very much,
ranMa

Assuming that you have a Perl or JScript scripting engine installed, you should just need to make the first line of the script

@script perl

or

@script jscript

(Or something like that. I have only used VBScript in Opus so I may have the names wrong.)

But, what function should I implement in order to use perl or jscript?

The same? "Rename_GetNewName"?

By the way, isn't JScript installed by default in Windows?

thx

[quote="ranma172"]But, what function should I implement in order to use perl or jscript?

The same? "Rename_GetNewName"?[/quote]
Of course.

Dunno. Maybe. :slight_smile: I've never used it myself, except for very simple webpage stuff.

Thanks nudel, but I can't make it work... :frowning:

So use VBScript then :slight_smile:

It might help us help you if you showed us what you had tried so far. :slight_smile:

I was a little curious as to how this would work with perl myself. So I did some experiments. The following seems to work fine:

[code]@script perlscript
use strict;
use warnings;

sub Rename_GetNewName
{
my $strFileName = shift;
my $strFilePath = shift;
my $fIsFolder = shift;
my $strOldName = shift;
my $strNewName = shift;

}[/code]
Although I cannot get Dopus.OutputString() to work in any way I was able to verify that these parameters are passed correctly (I used some illegal code and error output to get to this conclusion).

However, the biggest problem is that the last parameter strNewName is actually passed as a string and not as a reference. So there does not seem to be any way to actually set a new filename.

This does not work (for obvious reasons):

$strNewName = "some_new_name.txt";

Neither does this:

return "some_new_name.txt";

Has anybody managed to get scripts with any other language than vbscript to work properly in DO? Especially for Rename Scripting?

Same with DOpus.OutputString?

If not, maybe some of the devs has managed to do the same, as the language seems to be mentioned in relation to DO's scripting abilities?

It turns out that JavaScript doesn't support pass-by-reference arguments, so it's probably impossible to use it for Rename scripts. I think PhP had the same limitation.

I'm not sure about Perl, Python, etc., but if anyone has got anything other than VBScript to work then I think they've kept it to themselves as I don't remember any forum posts about it.

The statement that JScript and Perl should work probably came from my intro/guide or posts in threads like this, and may have been wrong. I'm fairly ignorant of exactly what the different scripting langauges can do and assumed that since they were supported by ActiveScipting then they would "just work". I may have been wrong.

In theory, though, if a language can plug into ActiveScripting and allows for pass-by-reference, then it should work as well as VBScript.

(It's possible nobody has bothered to work out how because it's quicker/easier to learn enough VBScript to get the job done. :slight_smile: It'd be nice to see other languages used, though, so that that learning curve isn't there for people unfamiliar with VBScript.)

Hi Nudel,
PHP does support pass-by-reference arguments.
Enigma and I dived into this some time ago here.

I tried PHPscript again a few minutes ago using the latest version of PHP5, 5.2.5, and found the same results as before.
As I recall, it was your post on this thread that nailed down the problem with PHPscript and DOpus.
I posted last on the thread, but it was my understanding that my results,
at a humble minimum, made pluasible your conjecture.

I really think it's abug in the PHP activescript dll.
This should work in PHP .

But then, what the hell do I really know ?
Thanks much Jon for your input on that thread !

Thanks Zippo. I'd forgotten the details of that thread and got the wrong reason for it not working.

[quote="nudel"]It turns out that JavaScript doesn't support pass-by-reference arguments, so it's probably impossible to use it for Rename scripts. I think PhP had the same limitation.

I'm not sure about Perl, Python, etc., but if anyone has got anything other than VBScript to work then I think they've kept it to themselves as I don't remember any forum posts about it.

The statement that JScript and Perl should work probably came from my intro/guide or posts in threads like this, and may have been wrong. I'm fairly ignorant of exactly what the different scripting langauges can do and assumed that since they were supported by ActiveScipting then they would "just work". I may have been wrong.

In theory, though, if a language can plug into ActiveScripting and allows for pass-by-reference, then it should work as well as VBScript.

(It's possible nobody has bothered to work out how because it's quicker/easier to learn enough VBScript to get the job done. :slight_smile: It'd be nice to see other languages used, though, so that that learning curve isn't there for people unfamiliar with VBScript.)[/quote]
This is the same conclusion I've reached, however it does support return values.

According to Perl documentation, Perl always use pass-by-reference, and modifies the original args if one doesn't copy and operate on the copy.

Problem is, it doesn't seem to work anyway for a reason..
Maybe a previous user was onto something when he mentioned that the strNewFilename is really passed by value and not by reference?

One strange thing though.. I've pondered on why DO use 'Function' in vbscript by default when it doesn't handle any return values, not even in vbscript? 'Sub' would've been more appropriate.

If it had handled returnvalues the same it does strNewFilename, and doesn't discriminate among those (i.e if you return a value, or you set strNewFilename, you would get the same result) then rename scripting would support any scripting language, pass-by-reference or not, as long as it at least supported returnvalues.

VBScript is nice for some basic things (I guess the name tells it all),
but it gets somewhat weak compared to other languages when it comes to more advanced scripting.

I agree with you that Perl is a beast (as you mentioned somewhere), but it is an extremely powerful beast.

I agree it would make sense for the rename function to return the new string, and pass in the existing string by value. No reason to exclude other languages unnecessarily. Same with underscores in the function names if they cause problems with PhP.

I don't know whether it's possible to change this without breaking existing rename scripts. If Opus can ask the ActiveScript engine which function names are available in the script then it should be easy to do, I expect, but I don't know what ActiveScript lets you do.

Worst case is existing scripts get broken and have to be slightly modified, perhaps.

[quote="nudel"]I agree it would make sense for the rename function to return the new string, and pass in the existing string by value. No reason to exclude other languages unnecessarily. Same with underscores in the function names if they cause problems with PhP.

I don't know whether it's possible to change this without breaking existing rename scripts. If Opus can ask the ActiveScript engine which function names are available in the script then it should be easy to do, I expect, but I don't know what ActiveScript lets you do.

Worst case is existing scripts get broken and have to be slightly modified, perhaps.[/quote]

Since the default Rename function is a 'Function' rather than a sub it the host (DO) might already be prepard to receive returnvalue, but it doesn't do anything with it yet.
But jon would know I guess.

However, a '_' removal would break existing scripts, but would only require that particular change..

Hey, that's one way one could do it.. when the @script parameter is phpscript (and maybe other known engines which do the same as phpscript) call it without the '_', otherwise do the same as it always has.

This part really only applies to the developers of DO, and not the users as it wouldn't break a thing on the script side as I see it, because it already uses functions and not sub's/procedures with vbscript.

at least if it's done as I previously suggested.. i.e, use both return value and strNewFilename (If there is a different value in strNewName than was provided, use it, otherwise use the returnvalue if it exists).

Sorry for multiposting, but can't find a way to edit my post.