Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CryptoGraphic

macrumors newbie
Original poster
Jan 20, 2015
13
0
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?
 

kryten2

macrumors 65816
Mar 17, 2012
1,115
99
Belgium
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?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,837
8,605
A sea of green
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.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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.
 
Last edited:

CryptoGraphic

macrumors newbie
Original poster
Jan 20, 2015
13
0
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.
 
Last edited:

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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.

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.
 

CryptoGraphic

macrumors newbie
Original poster
Jan 20, 2015
13
0
To try it without the loop you would just remove the folder name and replace it with "$@".

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

CryptoGraphic

macrumors newbie
Original poster
Jan 20, 2015
13
0
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. =)
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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. =)

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.
 

CryptoGraphic

macrumors newbie
Original poster
Jan 20, 2015
13
0
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.

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.
 

paul1762

macrumors newbie
Jul 27, 2019
10
1
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. =)
did you get this to work?

I am trying to get a way of renaming my photo collection and would like to rename the file and also check the file extension using Automator and Exiftool, however I just want to rename in the same file.

could you let me know what worked for you and how you set Automator up?

Paul
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.