this leaves behind the renamed original image file. How do you remove the original file during this process?
Use either the -overwrite_original
or overwrite_original_in_place
option to exiftool
. The in-place option preserves filesystem information such as file creation time, access time, Finder tags, icon, etc., but takes slightly longer than the other option.
I would like all this to execute for all new images added to the folder.
For this, you need to utilize a feature of Mac OS called "Folder Actions". A Folder Action is triggered when changes occur to a folder that has the action attached. Folder Actions can be written in AppleScript, but your case is simple enough that Automator is suitable to create the action. For a well-documented walk-through, read the Ask Different blog article Folder Actions Tutorial: Automation, Meet the Filesystem.
Launch Automator
. Choose a Folder Action
type for your document.
You’ll be given a blank workflow with an option in the top bar to select the folder to which this Action should be bound. Click that popup menu and choose Other...
to select the folder that will contain images you want to have your IPTC tag applied to.
Save your Automator action, naming it something useful (such as Apply IPTC By-line
).
The following workflow steps are much less complicated than the AskDifferent blog article's steps. You only need 2 workflow steps: one to filter the workflow, so that only image files are passed to exiftool
; and a shell script step that runs exiftool
just as if you ran it on the command line.
Filter Finder Items: Under the Actions Library > Files & Folders, drag the Filter Finder Items action to the workflow.
Run Shell Script: Under the Actions Library > Utilities, drag the Run Shell Script action to the workflow below the "Filter Finder Items" action.
Paste the following into the Run Shell Script text block:
export EXIFTOOL=/usr/local/bin/exiftool
for f in "$@"
do
$EXIFTOOL -iptc:By-line="mybyline" -overwrite_original_in_place "$f"
done
The workflow should look like the following:

Note especially that Pass input: is as arguments
(very important).
Note the first line (export EXIFTOOL=...
). While the location of exiftool
is likely in your own user's $PATH
(for instance, perhaps you used Homebrew to install Exiftool), the system's $PATH
variable that is used by Automator likely won't know where to find the exiftool
executable. To ensure the Automator workflow works correctly, open Terminal as you normally would, and enter the command: which exiftool
. The path that is returned should be pasted to the right of export EXIFTOOL=
on the first line in the Run Shell Script text block. **Important*: make sure there is no space between the =
character and the path you put there. A space character will break the script.
Save the Automator Folder Action.
Test it by copying an image file to the folder with Action attached. I emphasized "copying", because this action will modify what you place there. If something is broken, you don't want to potentially damage the only copy of the file you are using.
I also was thinking it would be great if I can capture the folder name that the images are in and add that name to the IPTC 'byline'.
This is the easy part. Just change the Run Shell Script text to the following:
export EXIFTOOL=/usr/local/bin/exiftool
for f in "$@"
do
dir="$(basename "$(dirname ${f})")"
$EXIFTOOL -iptc:By-line="${dir}" -overwrite_original_in_place "$f"
done
Just like the original shell script, this runs exiftool
for each file the Folder Action runs on. However, in this case, before we run exiftool
on each file, we save the file's directory name to the dir
variable:
$(dirname "${f}")
gets the path of the filename, without the filename itself (i.e., the dirname
of /Users/me/Pictures/TagIPTC/img_2112.jpg
would be /Users/me/Pictures/TagIPTC
.
dir="$(basename "...")"
gets the last portion of the path passed to it. Thus basename /Users/me/Pictures/TagIPTC
would just yield TagIPTC
.
Then, when we run exiftool
, we replace dir
with the each image file's containing folder name; i.e., the folder with the Folder Action attached.
Note
If you drag a folder containing image files, this action will not work.