Rename to exiftool.exe and change the path of exiftool in the script.
Code: Select all
//Function : Set tags and convert to hex set to metadata via Exiftool (https://exiftool.org/) (Rename to exiftool.exe and change the path of exiftool in the script)
//Created : 2022-07-18
//Modified : 2022-07-21
//Version : 1.1
$count = gettoken(get("selecteditemspathnames"), "count", "<crlf>"); //Count selected items
if($count == "0") {status "Nothing selected in the file list", "FF0000", "alert"; end '1==1'} //Abort, if no item(s) is selected
//Get tags
$taglist = formatlist(taglist(), "t", ", "); //Get taglist
$curitemTag = tagitems("tags", , "<curitem>", 1); //The tag(s) of the current item
$selItemsTag = tagitems("tags", , , 1); //Tag(s) of selected items
$selItemsTag = formatlist($selItemsTag, "sd"); //Remove duplicate tags of $selItemsTag
//$taglist - $curitemTag = $newtaglist
$newtaglist = "";
foreach($taglist1, $taglist, ", ", "e") {
$case = "";
foreach($curitemTag1, $curitemTag, ", ", "e") {
if($taglist1 == $curitemTag1) {$case = "1";}
}
if($case == "") {$newtaglist .= "$taglist1" . ", ";}
}
$newtaglist2 = substr($newtaglist, 0, -2);
//If $sleItemsTag contains empty tag(s) / Untagged item(s), set $case2 = 1, then break
foreach($selItemsTag1, $selItemsTag, "|") {
if($selItemsTag1 == "") {$case2 = "1"; break;}
}
switch($case2) { //Switch $case2
case "1":
$taglist2 = $taglist; //Show only list of tags
break;
default:
//Set $newCuritemTag separated by ", +"
$newCuritemTag = "";
foreach($curitemTag11, $curitemTag, ", ") {
$newCuritemTag .= "+" . "$curitemTag11" . ", ";
}
$taglist2 = "$newCuritemTag" . "$newtaglist2"; //Combination $newCuritemTag & $newtaglist2
}
//Pops up a window to set the tags
$data = inputselect("Set Tags/Metatags (Note: writing metadata will change file size/hash)<crlf>Tick the tags that shall be assigned to the selected items.", "$taglist2",", " ,3:=2+64+4096, "cancel", 500, 665, "XYplorer", , ":tagsset");
if($data == "cancel") {end '1==1';}
tag($data, , 1, 1); //Set new tag(s) to selected items
$newData = "";
foreach($tag1, $data, ", ") {
$hexdump = hexdump($tag1, 1, r); //Text to hex
$hexdump = replace($hexdump, " ", ""); //Replace space
$newData .= "$hexdump" . ";"; //Stack hex list
}
$taggedItems = "";
foreach($item1, "<get selecteditemspathnames>", "<crlf>") {
$result = runret("""D:\Tools\Exiftool\exiftool.exe"" -charset filename= *-wm* -*TAG*=$newData ""$item1"""); //Write metadata to each of the selected files via Exiftool
if(regexmatches($result, "1 image files updated")) {$taggedItems .= "$item1" . "<crlf>";}
}
//Status
//Status
switch($count) {
case "1":
if($data == "") {status "1 item untagged (Tags) | settings saved: Tags"; end '1==1';}
status "1 item tagged (Tags: $data) | settings saved: Tags";
break;
default:
if($data == "") {status "$count items untagged (Tags) | settings saved: Tags"; end '1==1';}
status "$count items tagged (Tags: $data) | settings saved: Tags";
}
if($taggedItems != "") {echo "Items that have been metatagged:<crlf><crlf>$taggedItems";}
//Show the metatag of the selected items
/*
foreach($item2, "<get selecteditemspathnames>", "<crlf>") {
if(exists($item2) != "2") {$metatag = runret("""D:\Tools\Exiftool\exiftool.exe"" -charset filename= -*TAGSLIST* ""$item2""");} //If $item2 is not a folder, read the metadata of each file via Exiftool
if(regexmatches($metatag, ";")) {
$metatag = gettoken($metatag, 2, ": ");
$metatag = gettoken($metatag, 1, "<crlf>");
$taglist3 = "";
foreach($metatag1, $metatag, ";", "e") {
$text2 = hexdump($metatag1, 1, "ri"); //Hex to text
$taglist3 .= "$text2" . ", "; //Stack tags list
$taglist33 = substr($taglist3, 0, -2);
}
text "$item2<crlf><crlf>$taglist33", 1200; //Show item and tags
}
$metatag = "";
}
*/