Skip to main content
New Participant
August 25, 2010
Question

Read metadata from file

  • August 25, 2010
  • 2 replies
  • 4817 views

Hi,

I have a plugin which executes ExifTool for some selected pictures. After ExifTool returns, I would like to reload the metadata from the changed files, so the change becomes visible to the user right away.

Basically, let my plugin perform the task of right-clicking an image and choose 'Metadata' -> 'Reload metadata from file'.

Unfortunately I haven't found a way in the API to do so. Can you point me to the right place?

Thanks,

Alex

This topic has been closed for replies.

2 replies

john beardsworth
Community Expert
August 25, 2010

It depends what you are trying to do. If you want to modify adjustment metadata, you can't. If you want to read descriptive metadata, make your plug-in tell exiftool to generate an xmp extract, parse that, and update the appropriate fields.

John

areohbee
Brainiac
August 26, 2010

Begging the question for Alex - can you have your plugin update the metadata fields directly? or does it have to be a Lightroom Read Metadata?

JW Stephenson
Inspiring
August 26, 2010

Here is some more information on what I am trying to do:

I have a G1 camera and an adapter to use an old manual Minolta AF lens with it. The pair produces nice pictures, however, since the adapter is mechanically only, the camera isn't able to write the Lens, ApertureValue and FocalLength values into the EXIF info of the photo.

That's where LR comes into the picture. I have all my pictures in LR and want to add the Lens info manually to the raw files. Since LR doesn't allow it (only IPTC data), I was looking for a different way to do this. I ended up with writing a plugin for that task. What the plugin does, is simply present a dialog to the user to let him enter the lens info, retrieves the list of selected photos and executes ExifTool for each picture. This works fine, but the newly written EXIF info does not show up in LR sidebar in the EXIF view. It, of course, only comes up as soon as you click on 'Reload Metadata from Files'.

What I was looking for, is a method to to the last step automatically by the plugin. This, however, seems to be a problem. You told me that there is no API functionality for it and even HotKey scripting is not a solution, since this menu entry has no hotkey assigned to it. :-(

Any other suggestions?

(but thanks so far!)

---

local function updateExif()

     -- get the path of the selected photo

     catalog = LrApplication.activeCatalog()

     photos = catalog:getTargetPhotos()

     -- invoke ExifTool for each picture

     for loop, photo in ipairs(photos) do

          pathName = photo:getRawMetadata('path')

          LrTasks.execute('exiftool -overwrite_original -Lens=\"' .. properties.lens .. '\" -FocalLength=\"' .. properties.focalLength .. '\" -ApertureValue=\"' .. properties.aperture .. '\" ' .. pathName)

     end

     LrDialogs.message( "EXIF Complete", "Done processing " .. #photos .. " pictures. You have to reload the metadata from the files now.", "info" );

end


Alex,

Like Rob, I too would like Lr:SaveMetadata and Lr:ReadMetadata functions (and a few more of course).  I had the same problem as you whereby I had scans that I wanted to enter the scanner name and model, and create a CreateDate as well.  The code I have under JeffScanMetadataFill.lua does basically what you are doing in your code above except I execute a keyboard macro (AutoHotKey) before to save the metadata at that state, then I change the fields in the image file via Exiftool like you do, then I execute another keyboard macro to read the metadata from the file.

These macros are a bit risky since they don't always know the state of your computer when they are running but I have found out that by selecting a small subset of images (less than 100) and not touching the computer while they are running I have had no problems.

I don't know how to attach files as I would like to share the lua code and the autohotkey scripts.  I am traveling and my email is jeff.laptop at cox.net if you wish to email me I can send you a zip file.  Or if someone knows how to attach a zip file to this forum I would be happy to post.

Bottom line, it can be done but I hope for a LR solution soon.

Jeff

areohbee
Brainiac
August 25, 2010

I don't think the API supports it. Keyboard stuffing is only way I know to do it. e.g. AutoHotKey(Windows) - dunno 'bout Mac.

Alex_fraAuthor
New Participant
August 25, 2010

Hey Rob,

thanks for your quick answer. But what the heck is an autokey script? :-)

Is there any reading material about it?

Alex

(And on a sidenote: why isn't such a basic functionality in the API? Especially as it is possible to execute third party applications which most probably are invoked to apply some changes to the pictures or its metadata. I am a bit puzzled...)

areohbee
Brainiac
August 25, 2010

Look up AutoHotKey on the net. It stuffs keystrokes into the keyboard buffer, simulating a user's typing.