Question about jscript based rename script syntax

WinXp sp3:

Anyone know why the following rename script code throws a basic / novice seeming "object expected" error:

[code]@script jscript

function Rename::GetNewName2 ( strFileName, strFilePath, _fIsFolder, strOldName, strNewName ){
alert(strFileName);
strNewName = "";
}[/code]
Like so...

Successfully initialized 'jscript' engine Script started successfully Error at line 2, position 1 Object expected Script error - script aborted
And related... what would the jscript equivalent of the vbscript based Dopus.OutputString() function be...?

It's because alert isn't a built-in function of JScript; it's provided by the 'window' object of web browsers, and thus not there in scripts that run inside something else (e.g. Opus).

The JScript Messages for Non-Browser Applications note by oddacorn in the Community Content section below MSDN's Using Message Boxes (Windows Scripting - JScript) page suggests using the WScript.Shell object, which I just checked works inside of Opus.

Here's an example rename script that does what you were trying to do:

[code]@script jscript

function Rename::GetNewName2 ( strFileName, strFilePath, _fIsFolder, strOldName, strNewName ){

var Shell = new ActiveXObject("WScript.Shell");
Shell.Popup(strFileName, 0, "Test Message Box", 0x30);

strNewName = "";
}[/code]

You almost had it. :slight_smile: JScript appears to be case-sensitive and the object is called DOpus rather than Dopus:

DOpus.OutputString(strFileName);

Ah damn... thanks. Ok, so I "get it" all now. Thanks for the MSDN reference... makes sense as the error indicates something at that spot in the script is unknown or undefined or whatever.

Yeah, at some point I "knew" the proper case syntax of DOpus.OutputString, and have it being used correctly even in non-case sensitive rename scripts of my own making... but was hacking together a jscript version of that moviedb thing, and re-using the incorrect case syntax from that other vbscript based rename preset. Woopsy...