Line 0 error messages with scripting

Advanced Renamer forum
#1 : 30/08-13 13:59
Ash Brown
Ash Brown
Posts: 2
Hi,

Does scripting actually work with normal javascript? My script is coming to a halt at line zero:

Invalid script: line 0: _itemFunc is not defined

Is it something basic I'm doing properly in AR? Any help appreciated.

My script is supposed to split a file name, change one part, put it back together and rename the file, e.g.
Smith_987654_replace.jpg

The split parts would be [0]Smith [1]987654 [2]replace. Then I do some math with the number and put it back together - but I'm not getting off the starting blocks. My script so far:

function(index, item) {
var n = item.newBasename.split('_');
nNew = parseInt(n[1]);

nNew = (nNew x 2);
nNew = nNew.toString;
len = (nNew.length)-6;
nNew = nNew.substring(len);
item.newBasename = n[0]+nNew+n[2];
return item.newBasename;
}

Many thanks for any help,

Ash


30/08-13 13:59
#2 : 31/08-13 16:14
Kim Jensen
Kim Jensen
Administrator
Posts: 871
Reply to #1:
The "_itemFunc is not defined" error happens when you have a syntax error in your script. Advanced Renamer wraps up the script into a function (_itemFunc) and compiles it before the batch is run. This is unfortunate because the error is not explained very good. But when I copy/paste the script into my Chrome script executor, I don't get better explanation of the error.

Your error is on the line with:
nNew = (nNew x 2);
The correct way to write this is:
nNew = (nNew * 2);

Also, the ( ) is not necessary.

You have two more errors in your script. You are missing ()
nNew = nNew.toString;
should be
nNew = nNew.toString();

In the end of the function you should not set item.newBasename. Instead you should just return the new name:
item.newBasename = n[0]+nNew+n[2];
should be
return n[0]+nNew+n[2];


31/08-13 16:14 - edited 31/08-13 16:20
#3 : 02/09-13 10:28
Ash Brown
Ash Brown
Posts: 2
Reply to #2:

That is indeed very helpful - apologies for my awful scripting, I work on pictures usually :)

Script works fine, with your fixes - thank you Kim.

Ash


02/09-13 10:28