Reputation: 651
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!
Upvotes: 0
Views: 1602
Reputation: 37288
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.
Upvotes: 1