我的最终解决方案:
将以下脚本(从 damienfrancois 答案修改)保存到文件,例如“photos.sh”。
IFS=$'\n';
for file in $(find ./ -name '*.jpg' -or -name '*.JPG' -or -name '*.tif' -or -name '*.JPEG'); # iterate over each file
do
taglist="$(tag --no-name --list "$file")" # get a comma-separated list (string) of tags
IFS=',' read -ra tagarray <<< "$taglist" # convert that string to an array
for tag in "${tagarray[@]}" # loop over that array of tags
do
exiftool -Keywords+="$tag" "$file" # add tag to file
done
done
不要忘记通过执行以下操作使脚本可执行
chmod 755 /path/to/script/dir/photos.sh
安装“JDBerry 的标签”并安装“Phil Harvey 的 ExifTool”。使用终端转到选择的目录。该目录必须只有“.jpg”、“.JPG”、“.tif”和“.JPEG”文件,脚本将递归遍历根目录但不会更改其他文件类型。成功的输出应该是这样的:
~ > cd /path/to/images/dir/
/path/to/images/dir/ > /path/to/script/dir/photos.sh
1 image files updated
1 image files updated
该脚本会将原始文件的副本保留为“img.jpg_original”。所有 Apple 标签将从最终文件“img.jpg”中删除。请记住在确定一切正常后删除“_original”文件(我使用了 Spotlight)。
我原来的问题:
我经常在 OS X 上使用终端来执行 rysnc、ssh 等任务,但我仍然是 bash 脚本的完全菜鸟。客户拥有大量使用 OS X 标签标记的图像。我需要将这些标签附加到 IPTC 元数据中。
到目前为止,我已经能够使用“JDBerry 标记”执行以下操作
~ > tag --no-name --list /path/to/img/example.jpg
Orange,Red
我还能够使用 Phil Harvey 的 ExifTool 执行以下操作
~ > exiftool -Keywords+='Orange' /path/to/img/example.jpg
1 image files updated
~ > exiftool -Keywords+='Red' /path/to/img/example.jpg
1 image files updated
是否有任何 Bash 脚本专家愿意并且能够帮助我?我正在考虑以下内容(用伪代码编写):
$imgDir[] = function that adds all images in directory to array;
foreach ($imgDir as $pathToImg) {
$tagsArray[] = function that executes "tag --no-name --list $pathToImg" and saves return value;
$numberOfTags = count($tagsArray);
if ($numberOfTags != NULL) {
for ($i = 1; $i <= $numberOfTags; $i++) {
function that executes "exiftool -Keywords+='$tagsArray[$i-1]' $pathToImg;"
}
}
}