script - rename based on ExifTool details
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?
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?
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>");
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>");
thanks a lot!