使用 Automator & 将 custo IPTC 关键字添加到 jpg出口工具

发布于 2024-11-26 11:47:14 字数 2523 浏览 1 评论 0原文

我已经搜索了我的*,但找不到任何对我有意义的东西。

我想在 Finder 中选择 jpg,并使用上下文菜单中的服务选项将关键字附加到图像。 我使用 Automator 来请求关键字并将其存储在变量中。

接下来的事情是使用带有 exiftool 的 shell 脚本来附加关键字。

问题是编写一个处理这两个变量的 shell 脚本(其中一个当然是包含文件名的数组)

我发现了一个非常有趣的博客条目: http://coreygilmore。 com/blog/2010/05/07/passing-multiple-automator-variables-to-a-shell-script/

执行此操作:

但我发现 Shell 代码太混乱了,无法 每个文件
exiftool IPTC:Keywords+="$MyKeywordsString" $file

请帮助我! 我想 Applescript 也可以工作,但我也不知道如何编写它......

提前致谢!

@shellter: 它不起作用,这是我的终端输出:

Last login: Thu Jul 28 19:57:54 on ttys000
localhost:~ benjamin$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
localhost:~ benjamin$ export Keywords=testKeyword
localhost:~ benjamin$ echo $Keywords
testKeyword
localhost:~ benjamin$ /Users/benjamin/Desktop/myKeyWords.sh /Users/benjamin/Desktop/image.jpg /Users/benjamin/Desktop/image2.jpg 
/Users/benjamin/Desktop/myKeyWords.sh: line 1: $: command not found
File not found: Keywords=
======== /Users/benjamin/Desktop/image.jpg
ExifTool Version Number         : 8.61
File Name                       : image.jpg
Directory                       : /Users/benjamin/Desktop
File Size                       : 128 kB
File Modification Date/Time     : 2011:07:27 10:41:49+02:00
File Permissions                : rw-r--r--
File Type                       : JPEG
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Current IPTC Digest             : c76c591fd016b068e1b44202c9f1996c
Keywords                        : MeinNeuerTag, MeinNeuerTag
Application Record Version      : 4
Comment                         : CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90.
XMP Toolkit                     : XMP Core 4.4.0
Image Width                     : 600
Image Height                    : 601
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 600x601
    1 image files read
    1 files could not be read

Why does it treat keywords as a file? 我必须将脚本放在哪里才能仅键入“脚本参数参数”而不是路径?抱歉,当我输入“echo $PATH”时,我对终端回显的内容一无所知,也许你可以帮助我。

再次感谢您!非常感谢!

I have searched my * off but couldn't find anything that made sense to me.

I would like to select jpgs in the Finder and use the services option in the context menu to attach a keyword to the images.
I use Automator to ask for the Keywords and store it in a variable.

Next thing would be to use a shell script with exiftool to attach the keyword.

Problem is to write a shell script that works with those two variables (one of them is an array of course containing the file names)

I have found one very interesting blog entry:
http://coreygilmore.com/blog/2010/05/07/passing-multiple-automator-variables-to-a-shell-script/

but I find Shell code too confusing to do this:

for everyFile
exiftool IPTC:Keywords+="$MyKeywordsString" $file

Please help me!
I guess Applescript would work too but I don't know how to write it either…

Thanks in advance!

@shellter:
It didn't work, here is my Terminal output:

Last login: Thu Jul 28 19:57:54 on ttys000
localhost:~ benjamin$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
localhost:~ benjamin$ export Keywords=testKeyword
localhost:~ benjamin$ echo $Keywords
testKeyword
localhost:~ benjamin$ /Users/benjamin/Desktop/myKeyWords.sh /Users/benjamin/Desktop/image.jpg /Users/benjamin/Desktop/image2.jpg 
/Users/benjamin/Desktop/myKeyWords.sh: line 1: $: command not found
File not found: Keywords=
======== /Users/benjamin/Desktop/image.jpg
ExifTool Version Number         : 8.61
File Name                       : image.jpg
Directory                       : /Users/benjamin/Desktop
File Size                       : 128 kB
File Modification Date/Time     : 2011:07:27 10:41:49+02:00
File Permissions                : rw-r--r--
File Type                       : JPEG
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Current IPTC Digest             : c76c591fd016b068e1b44202c9f1996c
Keywords                        : MeinNeuerTag, MeinNeuerTag
Application Record Version      : 4
Comment                         : CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90.
XMP Toolkit                     : XMP Core 4.4.0
Image Width                     : 600
Image Height                    : 601
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 600x601
    1 image files read
    1 files could not be read

Why does it treat Keywords as a file??
And where do I have to put the script to just type "script argument argument" instead of the path? Sorry I don't know anything about the stuff my Terminal echoed when I typed in "echo $PATH" maybe you can help me with that.

Thank you again! Much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月夜 2024-12-03 11:47:14

您可以将文件名视为位于数组中,但从 shell 的角度来看,可能更容易认为它们只是一个列表。

您需要制作一个脚本,例如

$ cat myKeyWords.sh
#! /bin/bash -vx

for file in "${@}" ; do
  exiftool Keywords="${myKeyWord}" "${file}"
done

创建文件后,您需要制作它以便系统有权运行它。
执行chmod 755 myKeyWords.sh。您需要将此脚本放在您的 Automater 工具知道的目录中,或者放在 PATH 中。执行 echo $PATH 来查看其中的值。如果有一个名为 /usr/local/bin,那可能是放置新脚本的最佳位置。

您必须参阅有关如何将关键字值从 Automater 传递到 shell 脚本的博客文章。如果你幸运的话它就会起作用。

该脚本打开了 shell 调试模式(第一行的 -vx)。您应该能够看到脚本内部发生了什么,因为调试将显示脚本中每个(以及大多数)步骤正在执行的内容。

我建议在 Automator 中使用脚本之前先确保该脚本可以独立运行。在终端窗口中打开,然后将其设置为:

export Keyword=xxxxx
myKeywords.sh file1 file2 file3 ...

当它完全按照您的需要工作时,您可以删除脚本第一行中的 -vx

此脚本还假设您的系统上有 /bin/bash,请根据需要更改该值以运行可用的 shell,/bin/sh、/bin/ksh、/bin/zsh,您可能需要将路径 /bin/ 更改为 /usr/bin 才能找到 shell。

我真的不认为您想要使用 keywords+="$myKeywordsString" ,因为每次脚本通过该分配时,关键字的值都会增加。您可以通过在调试模式下查看输出来确认这一点。

我希望这有帮助。

PS,由于您似乎是新用户,如果您得到的答案对您有帮助,请记住将其标记为已接受,和/或给它 +(或 -)作为有用的答案。

you can think of the fileNames as being in an array, but it might be easier to conceive that from the shell point-of-view, they are just a list.

you need to make a script like

$ cat myKeyWords.sh
#! /bin/bash -vx

for file in "${@}" ; do
  exiftool Keywords="${myKeyWord}" "${file}"
done

Once you have created the file, you need to make it so the system has permission to run it.
do chmod 755 myKeyWords.sh. You need to put this script in a directory that either your Automater tool knows about, or that is in the PATH. Do echo $PATH to see what values are there. If there is one called /usr/local/bin, that is probably the best place to put your new script.

You'll have to refer to the blog post on how to pass the value of Keywords from Automater to your shell script. If you're lucky it will just work.

This script has shell debugging mode turned on (the -vx on the first line). You should be able to see what is happening inside the script, as the the debugging will show what is being executed for each (well most) steps in the script.

I would recommend making sure the script works on its own, before going to use it in Automator. Open at terminal window, and set it up like :

export Keyword=xxxxx
myKeywords.sh file1 file2 file3 ...

When it is working exactly as you need it, you can remove the -vx in the first line of the script.

This script also assumes that /bin/bash is available on your system, change that value as needed to run the available shell, /bin/sh, /bin/ksh, /bin/zsh, you may need to change the path /bin/ to /usr/bin to find the shells.

I don't really think you want to user Keywords+="$myKeywordsString", as that will grow the value of Keywords each time the script passes thru that assignment. You can confirm that by looking at the output in debugging mode.

I hope this helps.

P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文