0

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

我想在 Finder 中选择 jpgs 并使用上下文菜单中的服务选项将关键字附加到图像。我使用 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 也可以,但我也不知道怎么写……</p>

提前致谢!

@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

为什么它将关键字视为文件?我必须将脚本放在哪里才能输入“脚本参数参数”而不是路径?抱歉,我对输入“echo $PATH”时终端回显的内容一无所知,也许您可​​以帮助我。

再次感谢你!非常感激!

4

1 回答 1

1

您可以将文件名视为一个数组,但从 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。

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

我希望这有帮助。

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

于 2011-07-27T00:53:01.320 回答