Automator and Exiftool

Discussion in 'Mac Programming' started by CryptoGraphic, Mar 13, 2015.

  1. CryptoGraphic macrumors newbie

    Joined:
    Jan 20, 2015
    #1
    Hi. I run exiftool in terminal and it work very well for me as below:

    exiftool '-FileName<DateTimeOriginal' -d %y%m%d%H%M%S%%-c.%%le MyPhotoFolder

    Now i want to create a service with automator that run above command for a folder in finder and rename all photos with exif info. I tried that in automator but it doen not work:

    for f in "$@"
    do
    exiftool '-FileName<DateTimeOriginal' -d %y%m%d%H%M%S%%-c.%%le "$f"
    done

    Any advice?
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    You can try using the full path to where exiftool is located e.g. /path/to/exiftool
    Are you using Pass input: as arguments in the Run Shell Script action?
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    Post any error message that appears when it doesn't work. Copy and paste it exactly; don't retype it manually or paraphrase it. Accuracy is important in programming.
     
  4. subsonix, Mar 13, 2015
    Last edited: Mar 13, 2015

    subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #4
    Automator scripts doesn't have an attached terminal so you will never see anything from the code above. If you want to rename the files based on the output from exiftool you need to save the result in a variable and use that to rename the file. You'd also need to parse the file extension from the file and add that back to the new name.

    Edit: Actually, looking at the exiftool it appears all that happens magically with that single line of code, it's a monstrosity. :)

    The code you said worked in terminal was:

    Code:
    exiftool '-FileName<DateTimeOriginal' -d %y%m%d%H%M%S%%-c.%%le MyPhotoFolder
    
    However in Automator you have a loop that iterates over all items in the directory, where "$f" carries the file name of each item in turn. Since exiftool as used in the terminal takes a directory as argument, try to remove the loop in Automator.
     
  5. CryptoGraphic, Mar 13, 2015
    Last edited: Mar 13, 2015

    CryptoGraphic thread starter macrumors newbie

    Joined:
    Jan 20, 2015
    #5
    If i try single line code -as in terminal- error is not detailed:

    The action “Run Shell Script” encountered an error.

    But i try second one that has a loop and there is no error. Seems like it's working but result has no change.

    Pass input is "to stdin" as default. Didn't try other one.

    subsonix i didn't undertand you exactly. Do you mean try single line code without loop? I tried single line code but it generates error. Can you write the code that you mean?

    Edit: Btw exiftool is a great tool. In Windows i use it in a .bat with only 2 line code and it rename all new photos, add date also to comment (in past facebook was getting comment automatically) and move them to final folder.
     
  6. CryptoGraphic thread starter macrumors newbie

    Joined:
    Jan 20, 2015
    #6
  7. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #7
    To try it without the loop you would just remove the folder name and replace it with "$@".

    I'm not dismissing exiftool in terms of it's capabilities with meta data. Looking at the man page, a short summary is this: "Read and write meta information in files" the issue is that it does so much more that is basically redundant replication of what you can do in a shell, it's a UNIX anti-pattern. If every tool did this you would need to learn fifty different ways to do the same thing in non standard ways.
     
  8. CryptoGraphic thread starter macrumors newbie

    Joined:
    Jan 20, 2015
    #8
    Code:
    exiftool '-FileName<DateTimeOriginal' -d %y%m%d%H%M%S%%-c.%%le "$@"
    or

    Code:
    do
    exiftool '-FileName<DateTimeOriginal' -d %y%m%d%H%M%S%%-c.%%le "$@"
    done
    generates same error. =|
     
  9. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #9
    I'm confused, marking only one folder, "$f" or "$@" are the same, use it as you did previously.

    Didn't see this, you need to use: as argument.
     
  10. CryptoGraphic thread starter macrumors newbie

    Joined:
    Jan 20, 2015
    #10
    Omg. Trick is really that: "Pass input as argument"

    Code:
    exiftool '-FileName<DateTimeOriginal' -d %y%m%d%H%M%S%%-c.%%le "$@"
    
    and

    Code:
    for f in "$@"
    do
    exiftool '-FileName<DateTimeOriginal' -d %y%m%d%H%M%S%%-c.%%le "$f"
    done
    all of them work perfectly anymore. Thanks man. You are the hero of the day for me. =)
     
  11. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #11
    Glad you got it working. Use the last example quoted above though. I confused a loop in terminal and marked files or folders being passed into Automator. With the above example you should be able to mark several folders in one go.
     
  12. CryptoGraphic thread starter macrumors newbie

    Joined:
    Jan 20, 2015
    #12
    Normally i use it only for one folder that i copy new photos. So other one is ok for me. And now i can select a folder or photos. These are extra and usefull for me.

    If you didn't say that i wouldn't try it for a long time because the post that i use as an example shows default one as working one. So thank you again.
     

Share This Page