0
\$\begingroup\$

I am new to Exiftool and have some experience with Mac Terminal. I am trying to add IPTC 'BY-line' meta to all images within a folder. This is what I have so far: exiftool -iptc:By-line='mybyline' /Users/username/Desktop/foldername. However, this leaves behind the renamed original image file. How do you remove the original file during this process?

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'. Example: imagesfolder/{images} , then make exiftool read the folder name of the image (in this case 'imagesfolder') and add that to the IPTC 'byline' exiftool -iptc:By-line='imagesfolder' /Users/username/Desktop/imagesfolder

How can I accomplish this?

And finally I am not sure if Exiftool can do this or not, but I would like all this to execute for all new images added to the folder. Another words when I add an image to this folder Exiftool will find the folder name and add the IPTC 'By-line' automatically.

Thanks for any help you can provide.

\$\endgroup\$
2
  • \$\begingroup\$ While use of exiftool is on-topic here at Photo.stackexchange, I believe that answers to this question primarily centers around Automator, Folder Actions, and perhaps Terminal scripting. It would more topical and more likely to get great answers over at the Apple SE, AskDifferent \$\endgroup\$
    – scottbb
    Apr 23, 2016 at 13:52
  • \$\begingroup\$ ... and then having said that, I went ahead and answered the question anyway. \$\endgroup\$
    – scottbb
    Apr 23, 2016 at 19:26

2 Answers 2

3
\$\begingroup\$

Repeating my response on the Exiftool forums for users of StackExchange.

Add -overwrite_original to avoid creating backups or use -delete_original to delete them when you're sure you don't need them anymore

To add the folder name, you can use the advanced formatting in this Exiftool forum post

Putting it all together, your command could be something like this:
exiftool -overwrite_original -iptc:By-line='mybyline ${directory;my @a=split m(/);$_=$a[-1]}' DIR

And @scottbb has the answer with regards to automation.

\$\endgroup\$
2
\$\begingroup\$

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.

  1. Launch Automator. Choose a Folder Action type for your document.

  2. 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.

  3. Save your Automator action, naming it something useful (such as Apply IPTC By-line).

  4. 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.

  5. 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:

    exiftool Automator Folder Action

    Note especially that Pass input: is as arguments (very important).

  6. 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.

  7. 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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.