Conditionally write to XMP file based on type of source file

Started by Joanna Carter, May 30, 2021, 08:24:54 AM

Previous topic - Next topic

Phil Harvey

Hi Joanna,

Your warning message contradicts the command you say you are using.  The warning indicates you are copying tags from the XMP file.

Why are you placing the options on separate lines?  Are you using an argfile?  What is the exact command you are using?

- 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 ($).

Joanna Carter

My apologies. I put the options on separate lines because that is how they are built in my software, one line per argument. They are all concatenated with one space between each argument when the command is about to be executed.

The Process is set up in code like this...


  {
    let process = Process()
   
    process.executableURL = appURL
   
    process.arguments = theListOfArguments // as you see from my previous post
   
    ...

    process.launch()
  }


If I copy the command line I end up with...

exiftool -preserve -ignoreMinorErrors -overwrite_original_in_place -mwg:keywords=Didier -tagsFromFile /Users/joannacarter/Pictures/JNA_0052.NEF '-SidecarForExtension<filetype' /Users/joannacarter/Pictures/JNA_0052.xmp

And I end up with "    1 image files updated\n" being returned from the executing the process.

Phil Harvey

OK.  So it works from the command line.  If it doesn't work from inside your app, then there is a difference in the way the arguments are parsed when you execute from within your app.  I can't help with this.

- 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 ($).

Joanna Carter

I've resorted to hand-crafting minimised copying arguments to test this out, as this seems to be where the problem lies.


let args = ["-v5", "-tagsFromFile /Users/joannacarter/Pictures/JNA_0052.NEF", "'-SidecarForExtension<filetype'", "/Users/joannacarter/Pictures/JNA_0052.xmp"]


This generates the following errors...


Invalid TAG name: "tagsFromFile /Users/joannacarter/Pictures/JNA_0052.NEF"
Error: File not found - '-SidecarForExtension<filetype'
Warning: Invalid tag name 'tagsFromFile /Users/joannacarter/Pictures/JNA_0052.NEF' - /Users/joannacarter/Pictures/JNA_0052.xmp


If I run the command in Terminal, I get a v5 output of...


Setting new values from /Users/joannacarter/Pictures/JNA_0052.NEF
Writing XMP-photoshop:SidecarForExtension
======== /Users/joannacarter/Pictures/JNA_0052.xmp
Rewriting /Users/joannacarter/Pictures/JNA_0052.xmp...
  FileType = XMP
  FileTypeExtension = XMP
  MIMEType = application/rdf+xml
    - XMP-photoshop:SidecarForExtension = 'NEF'
    + XMP-photoshop:SidecarForExtension = 'NEF'
    1 image files updated


For my generated args, am I splitting them in the wrong place?

Phil Harvey

...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 ($).

Joanna Carter

What kind of an answer is that?  :P ::)

As it happens, a good one but I was too tired to continue last night (didn't hit the sack until 2am)

Anyway, with a bit if persistence, here's the final arguments list...


    -preserve
    -ignoreMinorErrors
    -overwrite_original_in_place
    -mwg:keywords=Didier
    -tagsFromFile
    /Users/joannacarter/Pictures/JNA_0052.NEF
    -SidecarForExtension<filetype
    -format<mimetype
    /Users/joannacarter/Pictures/JNA_0052.xmp


One of the problems was that, in Terminal, you need to surround the copy arguments with single quotes, so I dutifully added them in to my generating code. I was also under the impression from the documentation (yes I have read it  ;) ) that the -tagsFromFile argument included the source filename, which is what led me to concatenate them in my generating code.

Now, the Swift code to generate a -TagsFromFile "phrase" is simply...


let tagsFromFileArgument = ExifCommand.Argument.tagsFromFile(sourceFilename: sourceFilename,
                                                                             destinationArguments: [.sidecarForExtension, .format],
                                                                             sourceArguments: [.fileType, .mimeType])


Thanks once again for your forbearance with an old girl still learning new tricks after thirty years in the game  8)

Joanna Carter

I just had to come on here and celebrate having got everything (so far) to work.

I can now write the same metadata to a RAW file and/or an XMP file, in any combination!

Here's the argument list for writing a keyword to both, all in one command...


  -preserve
  -ignoreMinorErrors
  -overwrite_original_in_place
  -mwg:keywords=Drill
  /Users/joannacarter/Pictures/JNA_0052.NEF
  -all=
  -tagsFromFile
  /Users/joannacarter/Pictures/JNA_0052.NEF
  -all
  -filetype>SidecarForExtension
  -mimetype>format
  -mwg:keywords=Drill
  /Users/joannacarter/Pictures/JNA_0052.xmp


This also takes care of the possibility of having two RAW files with the same name in the same directory. Last one written to rewrites the XMP file. Not a perfect solution but even the great Adobe can't do better.

I leave this message in appreciation of all the help I have received here and as searchable material for those who might have need to solve the same problem