Exiftool script: can someone help me please?

Discussion regarding all scripting related questions
Please DO NOT post to this thread anything that is not directly related to scripting of Capture One.

Exiftool script: can someone help me please?

Postby Marc Desimpelaere » Sun Dec 30, 2018 11:43 am

First post here.

I am using C1 v11 and trying to change EXIF for images I scanned from film.

What I want to do is change make/model and lens EXIF.

I produced this from bits and pieces I found on the web (see code below), but it doesn't seem to execute. I get error -10004. Can someone point me in the right direction as to what I am doing wrong.

Also (2nd question) if I want to change date/time, how would be the best way to proceed?

Any help greatly appreciated! Thanks in advance...

Code: Select all
set DefMake to "Pentax"

set theRespondedMake to the text returned of ¬
   (display dialog ¬
      "What's the camera make?" default answer DefMake ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")

set DefModel to "MX"

set theRespondedModel to the text returned of ¬
   (display dialog ¬
      "What's the camera model?" default answer DefModel ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")

set DefLens to "SMC"

set theRespondedLens to the text returned of ¬
   (display dialog ¬
      "What's the lens used?" default answer DefLens ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")

set DefAperture to 1.8

set theRespondedAperture to the text returned of ¬
   (display dialog ¬
      "What's the aperture value?" default answer DefAperture ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")

set DefFocalLength to 50

set theRespondedFocalLength to the text returned of ¬
   (display dialog ¬
      "What's the focal length?" default answer DefFocalLength ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")



tell application "Capture One 11"
   set selectedVariants to get selected variants
   repeat with i from 1 to number of items in selectedVariants
      set this_item to item i of selectedVariants
      set theID to id of (parent image of this_item)
      do shell script "/usr/local/bin/exiftool -overwrite_original_in_place -preserve -m " & ¬
         " -Make=" & theRespondedMake & ¬
         " -Model=" & theRespondedModel & ¬
         " -Lens=" & theRespondedLens & ¬
         " -EXIF:ApertureValue=" & theRespondedAperture & ¬
         " -FocalLength=" & theRespondedFocalLength & ¬
         " " & quoted form of theID
      reload metadata this_item
   end repeat
end tell
Marc Desimpelaere
 
Posts: 8
Joined: Sat May 18, 2013 10:02 pm
Location: Belgium

Re: Exiftool script: can someone help me please?

Postby Eric Nepean » Mon Dec 31, 2018 3:24 am

The obvious error is that you are telling Capture One to run a shell script. You should be telling the current application, like the code below. That gets rid of the error, and works for my Olympus images, except that the new value of Aperture is not copied back into Capture One.

It may be the Capture One doesn't resynch this data, or it may be that it uses a different Metadata field.

Code: Select all
        tell current application to do shell script ¬
         "/usr/local/bin/exiftool -overwrite_original_in_place -preserve -m " & ¬
         " -Make=" & theRespondedMake & ¬
         " -Model=" & theRespondedModel & ¬
         " -Lens=" & theRespondedLens & ¬
         " -EXIF:ApertureValue=" & theRespondedAperture & ¬
         " -FocalLength=" & theRespondedFocalLength & ¬
         " " & quoted form of theID
Eric Nepean
 
Posts: 612
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Exiftool script: can someone help me please?

Postby Eric Nepean » Mon Dec 31, 2018 7:17 am

Here is my slightly modified version of the script with some notes about behaviour.

An important note is that removing a Metadata Tag from the file and then reloading the Metadata into Capture One does NOT result in Capture One removing that Metedata Tag from its data base. There is no way to cause Capture One to remove a Metadata Tag you no longer want.

Particularly tricky is the Focal Length Tag. For images taken with completely manual lenses, the Focal Length Tag is initially not present. If you add the Focal Length Tag with a value of say 55mm, no problem, Capture One will add it to it's database for that image.

But if you later decide that you didn't really know the focal length after all (as I did), removing the Focal Length Tag using ExifTool will result in Capture One retaining the 55mm value. If you set the Focal Length Tag to 0, Capture One will ignore it. The best I could manage is set the Focal Length Tag to 1mm.


Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set DefMake to "Pentax"

set theRespondedMake to the text returned of ¬
   (display dialog ¬
      "What's the camera make?" default answer DefMake ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")
## in case there are multiple words in the Make. But entering nothing will remove this Exif Tag
if 0 < length of theRespondedMake then set theRespondedMake to quoted form of theRespondedMake

set DefModel to "MX"

set theRespondedModel to the text returned of ¬
   (display dialog ¬
      "What's the camera model?" default answer DefModel ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")
## in case there are multiple words in the Model. But entering nothing will remove this Exif Tag
if 0 < length of theRespondedModel then set theRespondedModel to quoted form of theRespondedModel

set DefLens to "SMC"

set theRespondedLens to the text returned of ¬
   (display dialog ¬
      "What's the lens used?" default answer DefLens ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")
## in case there are multiple words in the Lens. But entering nothing will remove this Exif Tag
if 0 < length of theRespondedLens then set theRespondedLens to quoted form of theRespondedLens

set DefAperture to 1.8

set theRespondedAperture to the text returned of ¬
   (display dialog ¬
      "What's the aperture value?" default answer DefAperture ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")
## Entering nothing will remove this Exif Tag from the file
set DefFocalLength to 50

set theRespondedFocalLength to the text returned of ¬
   (display dialog ¬
      "What's the focal length?" default answer DefFocalLength ¬
      with icon note buttons {"Cancel", "Continue"} default button "Continue")
## Entering nothing will remove this Exif Tag from the file
## Entering "0" will result in Capture One ignoring it

tell application "Capture One 11"
   set selectedVariants to get selected variants
   repeat with i from 1 to number of items in selectedVariants
      set this_item to item i of selectedVariants
      set theID to id of (parent image of this_item)
      
      ## So that I can log it if necessary      
      set theExifToolCommand to ¬
         "/usr/local/bin/exiftool -overwrite_original_in_place -preserve -m " & ¬
         " -Make=" & theRespondedMake & ¬
         " -Model=" & theRespondedModel & ¬
         " -Lens=" & theRespondedLens & ¬
         " -EXIF:ApertureValue=" & theRespondedAperture & ¬
         " -FocalLength=" & theRespondedFocalLength & ¬
         " " & quoted form of theID
      
      tell current application to do shell script theExifToolCommand
      
      ##  Metadata tags which are removed from the image file will result in Capture One retaining the previous value.
      ## There is no way to cause Capture One to remove a Metadata tag, once it has loaded it.
      reload metadata this_item
   end repeat
end tell


Eric Nepean
 
Posts: 612
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Exiftool script: can someone help me please?

Postby Marc Desimpelaere » Mon Dec 31, 2018 8:04 am

Thanks Eric, greatly appreciated.

Do I understand correctly that the code
Code: Select all
if 0 < length of theRespondedMake then set theRespondedMake to quoted form of theRespondedMake


is used to leave the field as it is if nothing is entered?
Marc Desimpelaere
 
Posts: 8
Joined: Sat May 18, 2013 10:02 pm
Location: Belgium

Re: Exiftool script: can someone help me please?

Postby Eric Nepean » Mon Dec 31, 2018 2:15 pm

Marc Desimpelaere wrote:Thanks Eric, greatly appreciated.

Do I understand correctly that the code
Code: Select all
if 0 < length of theRespondedMake then set theRespondedMake to quoted form of theRespondedMake


is used to leave the field as it is if nothing is entered?

Without this, it works fine if I enter "Panasonic" or nothing. But if I enter "Olympus Imaging Corp.", which is the usual value for an Olympus camera, the Exiftool command willl fail as each word is taken as a separate argument, and ExifTool tries to treat "Imaging" as a file name.

To get around this problem, I put the results into quoted form, which causes the command string to contain 'Panasonic' or
'Olympus Imaging Corp.' (quotes included).

But now entering nothing results in '' (two single quotes). I suppose that doesn't really matter for this field, but to maintain the original behaviour of deleting the tag I added the condition if " 0< length of ... ".

For a Tag like "Maker", perhaps a better response might be to reject no input or a blank input; this can be done right in the "display dialog" command by adding those optionss.
Eric Nepean
 
Posts: 612
Joined: Sat Oct 25, 2014 8:02 am
Location: Ottawa

Re: Exiftool script: can someone help me please?

Postby Marc Desimpelaere » Mon Dec 31, 2018 3:49 pm

Got it, super!

Many thanks again!
Marc Desimpelaere
 
Posts: 8
Joined: Sat May 18, 2013 10:02 pm
Location: Belgium


Return to Scripting



Who is online

Users browsing this forum: No registered users and 2 guests