Batch file in terminal (Mac) doesn't work

Started by Infobleep, December 05, 2010, 10:49:53 AM

Previous topic - Next topic

Infobleep

Hi there

I am running exiftool on my Mac in terminal. However whenever I try to run a batch script I get the error: "File not found" but if I run the command not in the batch file but type out, it works. If anyone could tell me what I am doing wrong, I'd be grateful.

I started off by doing: chmod 755 "copyright-artist&IPTCcopies-mac"
Then to run the batch file I did:
./"copyright-artist&IPTCcopies-mac"

Here is part of the code I created:

: *******************************
: ** Artist - This will be my name regardless of who took the photo, unless the complete batch were by someone else **
set v+
exiftool '-EXIF:Artist=Photographer' -L -overwrite_original_in_place -P -r "toamend"
set v-
: *******************************


When I run that I get:
Error: File not found - toamend
    0 image files updated
    1 files weren't updated due to errors


However if I run the exiftool part outside of the batch script it works. For example:
exiftool '-EXIF:Artist=Photographer' -L -overwrite_original_in_place -P -r "toamend"
gives me:
    1 image files updated

If I add an option after "toamend" in the batch file, for example -k, it works but I get the error:
Ignored superfluous tag name or invalid option: -k
    1 image files updated


I don't know what I am doing wrong. I have created batch files in Windows before but never in Unix so it will be something simple.

Thank you for your help. Kind regards

alexs77

Hm, it says, that it can't find "toamend".

What's "toamend"? As you're using the -r option, I guess it's a directory? Where is this directory? It MUST be in the same directory, as you're currently in, when you're invoking the script. If it's not, or if you don't know / are unsure about the directory you're in, you'd better specify the complete path to the directory, eg: ... -r "/Users/You/Pictures/toamend"

Phil Harvey

Odd.  This is what I get on Mac OS X 10.6.5:

% cat "copyright-artist&IPTCcopies-mac"
set v+
exiftool '-EXIF:Artist=Photographer' -L -overwrite_original_in_place -P -r "toamend"
set v-

% ls -l toamend
-rw-r--r--  1 phil  staff  254947  5 Dec 11:01 toamend

% ./"copyright-artist&IPTCcopies-mac"
    1 image files updated

% printenv SHELL
/bin/tcsh


The one thing I did do was drop the comments from your script.  In a script, comment lines should begin with #, but I don't see how this could cause your problem.  Like alexs77 says, his should work as long as "toamend" is in the current directory when you run the script.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Infobleep

Thanks for both your replies. The directory is located in the same directory as the shell script.

My latest script in order to run a short test on just 1 file is now as follows:

$ cat "copyright-artist&IPTCcopies-mac"
# *******************************
# ** copyrightNotice - copy from EXIF Copyright **
set v+
exiftool '-IPTC:copyrightNotice<EXIF:Copyright' -L -overwrite_original_in_place -P -r "/volumes/Videos & photos/photos/test.jpg"
set v-
# *******************************
$
$ ./"copyright-artist&IPTCcopies-mac"
Error: File not found - /volumes/Videos & photos/photos/test.jpg
    0 image files updated
    1 files weren't updated due to errors
$
$ exiftool '-IPTC:copyrightNotice<EXIF:Copyright' -L -overwrite_original_in_place -P -r "/volumes/Videos & photos/photos/test.jpg"
    1 image files updated
$
$ ls -l "test.jpg"
-rwxrwxrwx  1 geg50160  staff  3061297  1 Dec 22:19 test.jpg


It works when I type it in directly but not in the shell script. I am running bash in Terminal on my Mac Snow Leopard.

Kind regards

Infobleep

#4
I created the following script. The first one is my command and the second is your one:

set v+
exiftool '-EXIF:Artist=Photographer' -L -overwrite_original_in_place -P -r "toamend"
set v-
set v+
exiftool '-EXIF:Artist=Photographer' -L -overwrite_original_in_place -P -r "toamend"
set v-


It produced the following output:
$ ./"copyright-artist&IPTCcopies-mac"Error: File not found - toamend
   0 image files updated
   1 files weren't updated due to errors
  8 directories scanned
 279 image files updated


If I swap them around when I get the error message last rather than first. The only difference I can see is that I typed my script into the Mac application TextEdit, where as I copied and pasted your script into TextEdit.

Sorry a correction. The first part originally came from a dos batch file which was originally created in notepad. Not that I can see why that would be a problem but perhaps it is. I've attached a copy of my script.

Kind regards

alexs77

Quote from: Infobleep on December 05, 2010, 11:44:25 AM
Thanks for both your replies. The directory is located in the same directory as the shell script.

It doesn't matter where the script is stored. The directory needs to be in the same directory you're currently in. Where the script is stored is of no importance.


QuoteIt works when I type it in directly but not in the shell script. I am running bash in Terminal on my Mac Snow Leopard.

Yes. I guess the directory "toamend" (or what it was called...) is not in the same directory as you're currently in.

Please run "ls" and post the output (if it isn't too long - if it's long, please pastebin it or attach it as a file).

Alexander

Infobleep

I got around the problem by copying and pasting what Phil typed for each of my lines and then manually editing every line of my code so that it matched on screen the code I previously amended from a batch dos file. That being originally created in Windows Notepad. It then worked.

After that I was speaking to a friend who pointed out that the carriage return in UNIX is not the same as the one in DOS. And so because I'd typed the script in Windows that was why it didn't work. TextEdit would recognise the return and not change it unless I did so, which I didn't but UNIX wouldn't recognise it. Of course I couldn't see the carriage return without using v and even if I had, I wouldn't have realised anything was wrong.

All along it was something very simple and I knew it had to be. I'm sure there is probably lots of literature about this difference on-line, if you know what to look for. However I didn't know what the problem was so found nothing of help in my searches. However, as ever, this forum was of help so thank you.

Kind regards

Phil Harvey

I'm glad you figured it out.  I actually thought of the newline problem but didn't think it could be the problem because exiftool gave the message that (what seemed like) the proper file didn't exist.  However, I think what was happening is that with DOS CR/LF, the CR was taken as part of the file name, and since it was invisible it didn't show up here.

Well done to figure out the problem.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).