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

Gubblebummer

macrumors newbie
Original poster
Sep 18, 2015
6
0
no luck so far and I wonder what I'm doing wrong...

I use a neat little program called Exif tool, this is a program line tool which can be used in the terminal. To speed up things (I litteraly have thousands of files to rename) I want to use an automated apple script.

The command I'm using right now is:

Automator
Run shell script

for f in "$@"
do
exiftool -ext m2ts "-FileName<DateTimeOriginal" -d "%Y%m%d_%H%M%S.%%e" "$f"
done


But no magic. What am I doing wrong?



More intel on the exif tool: http://u88.n24.queensu.ca/exiftool/forum/index.php?topic=5651.0
 
no luck so far and I wonder what I'm doing wrong...

I use a neat little program called Exif tool, this is a program line tool which can be used in the terminal. To speed up things (I litteraly have thousands of files to rename) I want to use an automated apple script.

Aaaah... exiftool. :) I love it and hate it in equal measure. Very powerful but a bit counter intuitive, in my opinion.

First question I'd ask is what happens if you run the exiftool command in Terminal? What error(s) does it give you?

My second question would be why you're using exiftool? No reason not to, but there are other ways. I'd probably do it something like this:

Code:
theFilePath="/path/to/your/file"
theNewFileName=$(stat -f "%Sm" -t "%Y-%m-%d_%H%M%S.m2ts" "$theFilePath")
theFolder=$(dirname "$theFilePath")
mv "$theFilePath" "$theFolder/$theNewFileName"


Just to be slightly pedantic - none of this uses AppleScript. It's shell scripting and Automator so far. If you wanted to run a shell script as part of an AppleScript then that's pretty easy. Take a look at "do shell script"
 
Last edited:
Thx for the quick reply!

1/ if I run the exiftool command in terminal,

-ext m2ts "-FileName<DateTimeOriginal" -d "%Y%m%d_%H%M%S.%%e"

everything goes as planned, filename changes in the one I need.

2/ I use exiftool because the only usable recording time data is saved in a exif data tag that is out of the ordinary -> DateTimeOriginal
(it is a .mts file recorded by a Sony FS700)
 
I know very little about AppleScript, but when you call exiftool on a file within your AppleScript, shouldn't you be including the full path to the file you're trying to rename?
 
I know very little about AppleScript, but when you call exiftool on a file within your AppleScript, shouldn't you be including the full path to the file you're trying to rename?

I know too little as well, but I believe the

for f in "$@"

part means it should take every file in the specified folder (the one I rightclick)
 
I know too little as well, but I believe the

for f in "$@"

part means it should take every file in the specified folder (the one I rightclick)

Hmmm... well, exiftool is a *nix binary that runs in a standard shell environment. I'm curious as to what path exiftool is being executed in when it's called via your AppleScript. Can you dump environment variables from within the AppleScript to verify it's current path on execution?
 
I know too little as wel

The "Run Shell Script" automator action takes the output of the previous action as it's input. The shell script (it's a bash shell script, not AppleScript!) goes through each line of that text with 'f' as the current line each time.

I think there's a lot of merit in getting it working in the Terminal and then worrying about Automator. Did you try the common I suggested?
 
The "Run Shell Script" automator action takes the output of the previous action as it's input. The shell script (it's a bash shell script, not AppleScript!) goes through each line of that text with 'f' as the current line each time.

I think there's a lot of merit in getting it working in the Terminal and then worrying about Automator. Did you try the common I suggested?

I have it working in terminal:

-ext m2ts "-FileName<DateTimeOriginal" -d "%Y%m%d_%H%M%S.%%e"

works fine. What common do you mean? (I'm sorry for noobing)
 
Hmmm... well, exiftool is a *nix binary that runs in a standard shell environment. I'm curious as to what path exiftool is being executed in when it's called via your AppleScript. Can you dump environment variables from within the AppleScript to verify it's current path on execution?
How do I do this?
 
How do I do this?

Beats me. I've never used AppleScript. I write all of my scripts in either bash or perl.

Google searching yielded this thread which seems relevant:

http://stackoverflow.com/questions/24918497/applescript-run-bash-script-from-same-directory

Again, I don't know anything about AppleScript, but I just tried a basic: do shell script "pwd"

and it's definitely running from the "root" directory, which confirms my suspicious than in your case, it's not executing exiftool in the directory you wanted it to (running in root path and not the /path/to/your/files/in/question).
 
Let's get some simple things out of the way.

1. When "no magic" occurs (per 1st post), what is the error message in Automator?
Post the exact error message, if any. Look for error messages in Automator's log.

2. Where is exiftool located? Run this command in Terminal:
Code:
type exiftool
Copy and paste the output into a post here.
 
Let's get some simple things out of the way.

1. When "no magic" occurs (per 1st post), what is the error message in Automator?
Post the exact error message, if any. Look for error messages in Automator's log.

2. Where is exiftool located? Run this command in Terminal:
Code:
type exiftool
Copy and paste the output into a post here.


EDIT:
I know too little as well, but I believe the

for f in "$@"

part means it should take every file in the specified folder (the one I rightclick)
First, the mention of a right-click suggests you've created an Automator Service, which you then use from Finder.

Is this what you're doing?


Second, the "$@" input will NOT be every file in the folder you right-click. It will be whatever is selected when you right-click. If that's a folder, it's the pathname of the folder. If that's 12 files in a folder, it's 12 pathnames of the files in that folder.


I suggest stepping away from exiftool for a little while and first making sure the Automator action itself is correct, as well as the way you're running it. Once those basic elements have been confirmed as working correctly, we can go back and change the command to be exiftool.

Start with the default commands in a Run Shell Script action, with as arguments as the input option. Change the commands to this:
Code:
for f in "$@"
do
    echo "$f"  >>~/Desktop/TestOut.txt
done
Next, you need to inspect the actual output that's produced when this runs. That output will be in the file "TestOut.txt" that appears on your Desktop. You can open it in TextEdit.app or any text editor.

There will be one line for each argument. You'll be able to see for yourself exactly what happens when you right-click a folder. Make sure you understand what this Automator action does, and what the output means, even though it might not be what you want.

If the output isn't what you want, then post the output, and describe exactly what you want instead.

If there's no output, then say "There's no output, the file is empty", so we know exactly what happened.

For example, if the output is the pathname of a folder you right-clicked, then post the exact output and then say "I want the complete contents of this folder, rather than the folder itself".

We need to know exactly what you want to affect (the outputs), and exactly what the inputs are.
 
chown33's advice is good. Break it down step by step. Understand what each step is doing. If you don't understand what it's doing, post what you did and what happened (including errors etc) and we'll try to help you.

If your exiftool command is working fine from the Terminal then it suggests to me that your Automator action that tuns the shell script isn't doing what you think it's doing. chown33's advice will help you figure that out.

Also, maybe posting a screenshot of your Automator workflow might help too.

Lastly, none of this is AppleScript! It's Automator and shell scripting. ;-)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.