Automator/shell script minor issues

Discussion in 'Mac Programming' started by macstatic, May 11, 2016.

  1. macstatic, May 11, 2016
    Last edited: May 12, 2016

    macstatic macrumors 6502a

    Oct 21, 2005
    I'm working on a couple of Automator scripts containing shell commands which should work as drag & drop applications to put in the OSX dock (allowing files or folders where the image-files within will be processed by it). The terminal commands work fine in the OSX terminal but I'm having some minor issues when trying to adapt them for the script.

    Here's what the first script looks like. The "Get specified Finder items" points to a folder full of test images. There's a minor warning at the bottom (log) section, but this is just the same if I issue it in the OSX terminal and IMHO the script so far is working like it should.
    export PATH="$PATH:/usr/local/bin"
    for f in "$@"
    exiftool -r "-AllDates<MDItemContentCreationDate" "-XMP-Exif:DateTimeDigitized<MDItemContentCreationDate" -P -if 'not $exif:AllDates' -overwrite_original_in_place "$f"

    For comparison, here's the same command issued within the OSX Terminal:

    But if I run the script a second time I get a more serious error message. The script should check to see if the image(s) selected already have ann "AllDates" EXIF tag, and if so it should skip the file and move on to the next one. I suspect this is the cause for the error (as I've already run the script once to process the files, which adds this EXIF tag to the files which don't have them):

    Again, for comparison purposes, here's what that command looks like when issued from the OSX Terminal for the second time:

    What do I need to change in the Automator script to solve this issue?
    And is there a way I can have the summary results (1 directory scanned, 8 files failed condition, 9 image files updated) shown, perhaps in the alert window I've made using the Applescript action?
  2. piyush2508 macrumors newbie


    May 12, 2016
  3. chown33, May 13, 2016
    Last edited: May 13, 2016

    chown33 macrumors 604

    Aug 9, 2009
    The reports that say "Failed" are a result of exiftool's exit status.

    Compare these two commands:
    Neither one emits anything to stdout or stderr. Only 'false' fails in a Run Shell Script.

    As to collecting the output of exiftool, my best guess is that the summary you want to collect is appearing on stderr rather than stdout. Normally, the stdout of the command will become the text input to the next Automator step. You can try this using a few 'echo' commands.

    Redirection will put stderr onto stdout. Add this to your exiftool command line:
    I would have posted a modified command-line, but I can't copy and paste screenshots, and I'm not gonna risk typos by retyping that. It's more useful to copy and paste text (use CODE tags) when you post commands.

Share This Page