What script languages can be used with script rename?

I got this far with ActivePerl today:

[code]@script PerlScript
use Win32::OLE qw(EVENTS);

package MyEvents;
sub GetNewName {
$DOpus->OutputString("*** Sub called! ***");
}

package main;
Win32::OLE->WithEvents( $Rename, 'MyEvents', 'IDOpusScript_RenameEvent' );

$DOpus->OutputString("*** Main ***");[/code]

The "*** Main ***" message will be displayed, which is good, but then Opus will crash, which is bad.

The crash is happening inside of the ActivePerl DLL. Win32 OLE/Event support is said to be at "alpha" level and unstable/subject to change so my fear is that this simply won't work with Perl.

I think my script is right because if I change the $Rename to anything else, or the IDOpusScript_RenameEvent to anything else, then the crash does not happen and the sub is not called. So presumably the crash indicates that the sub is being called (or at least looked for), but then ActivePerl crashes the process.

I'm not sure where to go next, except maybe to ask for help on the ActiveState forums or try another language. :slight_smile:

(BTW, I was saddened to see that ActivePerl still installs to C:\Perl. Gah. It isn't 1985...)

Thanks much Jon !
Working on it in PHP Nudel.
Just a short late night PHP note:

The problem is that the Script completed line is never displayed when the $Dopus object or $Rename object is used.
I can write an arbitrary PHP script without using those objects and all is fine.
The Script Completed line is there !

$Rename members still error as undefined.
So, I'm wondering if another dll needs to be registered with regsvr32 ?
I tried php_win32std.dll and php_win32service.dll but is isn't proper.
It loaded with an error.
But then it is worthy to note that I only installed a "lite" copy of php guessing at what extensions I really needed.

Other than that I'm down to php.ini .....

I'm working on it though ...
Keep up the good work Nudel !
And thanks Jon !

[quote]I can write an arbitrary PHP script without using those objects and all is fine.
The Script Completed line is there ! [/quote]
Duh....
Tonight I'm not seeing the script completed line at all again.
Well, I'll try again after restoring my backup and installing a more complete version of PHP.

9.1.0.2 is out now and will try calling an alternative function/event which doesn't need pass-by-reference. Maybe that will make things work for some languages.

(I don't think it will help with Perl since Perl does let you set things by reference, and even has a specific thing for setting a ByRef variant string. The problem with Perl is it seems to crash when script events are called.)

[quote="nudel"]9.1.0.2 is out now and will try calling an alternative function/event which doesn't need pass-by-reference. Maybe that will make things work for some languages.

(I don't think it will help with Perl since Perl does let you set things by reference, and even has a specific thing for setting a ByRef variant string. The problem with Perl is it seems to crash when script events are called.)[/quote]

It at least works with JavaScript:

@script jscript
function Rename::GetNewName2 ( strFileName, strFilePath, _fIsFolder, strOldName, strNewName ){
 return strFileName.replace(/[._]/g,' ');
}

The above strips . and _ from filenames, all occurences, including the extension separator (just a test, so didn't bother with something fancy).

Btw, I noticed that the GetNewName2 doesn't use the [out,retval] flags on any variable, not sure of how this would affect things among the languages.

It works very well with Perl too:

@script perlscript
sub Rename_GetNewName2{
my( $strFileName, $strFilePath, $_fIsFolder, $strOldName, $strNewName )=@_;
  return "Test".$strFileName;
}

The above returns Test prepended on every filename. Nothing fancy, as I said.

Wonderful news myarmor !

Still nothing working here in PHP :frowning: :unamused:
I worked about two hours on it this afternoon.
I still can't see any values for the variants.
I've tried many things .....

It would be best to get PHP working as object oriented though.
The PHP5 syntax is quite nice then .
Well, we do have $DOpus->OutputString() !

Great stuff, myarmor!

I see now that I was making the Perl example far more complicated than it had to be. I could've sworn I had tried a simple sub called Rename_GetNewName2 before embarking on the Win32::OLE events crash-fest dead-end, but obviously I messed something up in all my faffing around. :slight_smile: Great to see it is worked out now, and so simple to boot.

I've summarised the different script syntaxes into a post over in the Rename forums:

[Rename scripts in JScript, VBScript and PerlScript)

I've written a great deal of php before, so I thought I should give it a try.. on the first run I remembered why I gave up using it with active scripting..

It kills the app/thread calling it if there are errors..or not.

This behaviour requires serious patience as a refocus of DO, then Ctrl+F2 etc must be done every time.

I like the language, but my previous conclusion regarding hosted scripting (activescript) with that language was that it is just too flakey..
Still..

Very nice for websites etc though.

[quote="nudel"]Great stuff, myarmor!

I see now that I was making the Perl example far more complicated than it had to be. I could've sworn I had tried a simple sub called Rename_GetNewName2 before embarking on the Win32::OLE events crash-fest dead-end, but obviously I messed something up in all my faffing around. :slight_smile: Great to see it is worked out now, and so simple to boot.

I've summarised the different script syntaxes into a post over in the Rename forums:

[Rename scripts in JScript, VBScript and PerlScript)[/quote]
I was a bit suprised myself as I too had begun experimenting a bit on the same as you.

When looking through the examples I noticed how the functionnames was named when using asp (vbscript style), so I just went back and tried it..and it worked. :slight_smile:

I've noticed you didn't especially like perl though.. There's no problem setting the install directory to "c:\program files\perl" in the installer (msi) though..

Somewhat nice with all the extra power.. Using some of the stuff that already exists for the language inside renamescripts.

I figured they must install to C:\Perl for some kind of technical reason as it's such a rude and ugly place to drop a program that they wouldn't unless they really had to. Maybe I'm wrong and they're just clueless/lazy about fixing their installer?

(I should say the same about NVidia whose driver installs drop stuff in C:\NVidia... Stuff that doesn't even need to stay on the HDD after you've rebooted... And those damn printer/scanner drivers that create stupid log files in C:... Ah, maybe it isn't just ActiveState, I had just filtered out the other offenders. :slight_smile: )

I hate Perl for lots of other reasons other than the ActiveState installer, but I mainly added the small-font rant to make people laugh. Maybe not everyone will find it funny... Ah, poop, I'll edit it out of the post as it doesn't really add anything useful. :slight_smile:

@nudel, You got what you wanted from me with that one then.. A laugh :slight_smile:
I had to concentrate a bit to stay serious.
No biggie. :slight_smile:

Okay, if I understand it correctly, there is a class (called RenameEvent or Rename) in which the member functions GetNewName and GetNewName2 are declared, but not implemented. Rename is an instance of this class.

Obviously in VBScript, Perl and JScript (not JavaScript, or am I wrong here?) it is possible to implement these member functions separately using

Rename_GetNewName

in VBScript and Perl and

Rename::GetNewName

in JScript. Is this correct? Well, in PHP I don't know any way to implement or redeclare a member function of an interface or an existing class other than defining a new (child) class - which has a different name - and instantiate a new object. I can't think of a way to make this work with the renaming script mode of DOpus...

myarmor, you seem to be quite experienced in writing scripts for the WSH. Maybe you know a way to get around this?

Cheers,
Jan

I can't help with PHP, but to answer your question about JScript vs Javascript, they are virtually the same thing according to the Wikipedia article:

en.wikipedia.org/wiki/JScript

The page lists a couple of the differences, which don't look like they'll matter for Opus rename scripts:
en.wikipedia.org/wiki/JScript#Di ... JavaScript

Yes, I know about that. :slight_smile: Sometimes I'm a little pedantic... :unamused:

Cheers,
Jan

Yes, I know about that. :slight_smile: Sometimes I'm a little pedantic... :unamused:

Cheers,
Jan[/quote]

In microsoft's case they are the same (and I think both names can be used).
The javascript engine registers with the name 'JScript', in addition to a couple of other JScript.xxxxx names.

As I mentioned earlier, I haven't been too successful with PHPscript, maybe due to my lack of patience regarding the behaviour I described.

Most likely you would use the same way to specify the handler as you normally would do in ASP with the same language.
I don't know ASP very well, but I've noticed it tends to be the exact same way.
If you would use the Rename_GetNewName2 format in ASP, then you most likely would use the same here.

Well, I've never heard of ASP scripts written in PHP, so this could be a little difficult. :wink:

The underscore is a legal part of PHP function names, so this doesn't work here - Rename_GetNewName2() would just be a new user function that has nothing to do with the object Rename. (BTW: The old function GetNewName() could be used, too, since PHP allows passing parameters by reference, so this new feature in DOpus is helpful for using JScript, but regarding PHP it doesn't change much.)

With Rename->GetNewName2() you could call a member function of the object Rename, and with Rename::GetNewName2() it's possible to call a member function of a class called Rename - but neither way it's possible to (re)define a function that's declared in an interface or defined in a class - and consequently DOpus crashes if you try to use one of these... :frowning: At the moment, I don't see a way around this.

Cheers,
Jan

[quote="Enigma"]
The underscore is a legal part of PHP function names, so this doesn't work here - Rename_GetNewName2() would just be a new user function that has nothing to do with the object Rename. (BTW: The old function GetNewName() could be used, too, since PHP allows passing parameters by reference, so this new feature in DOpus is helpful for using JScript, but regarding PHP it doesn't change much.)

With Rename->GetNewName2() you could call a member function of the object Rename, and with Rename::GetNewName2() it's possible to call a member function of a class called Rename - but neither way it's possible to (re)define a function that's declared in an interface or defined in a class - and consequently DOpus crashes if you try to use one of these... :frowning: At the moment, I don't see a way around this.

Cheers,
Jan[/quote]

I haven't tried it, but did you try using :: as separator?

I didn't even know Jscript supported the use of :: separator at all, and I haven't been able to find documention saying that it do, but still that format worked with JScript and DO.

At least it's no harm in trying.

Just to try expanding the list of known supported renamescript languages I've currently experimenting with a couple of languages (OORexx, HaskellScript) I don't know at all, but which also might work with DO with the proper definition.

Yes, I tried even those constructs that I was sure of that they won't work. They didn't work. :wink:

Cheers,
Jan

Yes, I tried even those constructs that I was sure of that they won't work. They didn't work. :wink:

Cheers,
Jan[/quote]

Ok, I'm currently out of ideas then. :confused: