script - rename based on ExifTool details

Advanced Renamer forum
#1 : 25/04-23 09:56
gr2y
gr2y
Posts: 2
Hi,
I would like to write the following script:
if
<ExifTool:Make> = "Canon" or "Apple"
rename image to
<ExifTool:CreateDate>

I'm trying the following, but there is an error (undefined not callable array..):
const arr = ["Canon", "Apple"];
const exifMake = item.exifToolValue("Make");
if (arr.includes(exifMake)) {
return item.newName = item.exifToolValue("CreateDate")
}

Could you please advise how to do it in a right way.

Also, as far as I understand from user_guide it is not possible to mix script and regular rules. In case I need any further filename modification I have to continue doing it in script OR I can add just another rule?


25/04-23 09:56 - edited 25/04-23 10:07
#2 : 25/04-23 11:56
David Lee
David Lee
Posts: 1125
make = item.exifToolValue("Make");
if (make == "Canon" || make == "Apple") {
return item.exifToolValue("CreateDate").replace(/:/g, "-");
}

ExifTool returns the date string using colons as separators, which is illegal in a Windows filenameso the above script uses the .replace method to replace ":" with "-". Note that global replacement (ie every instance of ":") is only possible if we use the regular expression version of the .replace method - ie . .replace(/:/g, "-").

Also, if the script contains an optional "return" statement the returned value is automatically assigned as the new filename.

Whilst you cannot use batch methods inside a script you can use app.parseTags() to extract the values of tags.

For example the above script could also use the code:
make = app.parseTags("<ExifTool:Make>");






25/04-23 11:56 - edited 25/04-23 12:00
#3 : 25/04-23 14:43
gr2y
gr2y
Posts: 2
thanks a lot!


25/04-23 14:43 - edited 25/04-23 14:44