Show EXIF metadata of pictures in DT?

That is one of the wonderful things about DEVONthink, in my experience. It’s so easy to click into another app to do even more with the file than DEVONthink does. It’s part of a great ecosystem.

1 Like

Whilst there is no direct way to extract that data using AS or JS, a quick internet search shows numerous methods of doing so; you could set up a smart rule to access the EXIF data of any photo using AS/JS, and automatically copy that data to custom metadata. Sure, that’s a workaround, but it should be quite doable.

There is a promising looking suggestion on how to extract EXIF data using JS on stackoverflow; I have not tested this myself, but the sample script looks as though it could be adjusted to suit. There are numerous examples of how to use JS in a smart rule here on the forums, and users who are usually prepared to point you in the right direction if you get stuck and post the code you are working on.

3 Likes

But there is:

(() => {
  const app = Application("DEVONthink 3")
  const IE = Application('Image Events');
  app.includeStandardAdditions = true;
  const recs = app.selectedRecords();
  // Loop over all selected records
  recs.forEach(r => {
   // Get path of current record
    const p = r.path();
   // Skip over every record that's not a jpeg image
    if (!(r.type() === 'picture' && /\.jpe?g$/i.test(r.path()))) 
      return;
    // Open the file as an image
    const image = IE.open(p);
    // Get the image's metadata
    const metaData = image.metadataTags();
    // Loop over the metadata
    metaData.forEach(m => {
      // If the current metadata is 'creation', get its value and
      // convert to a JS date
      if (m.name() === 'creation') {
        const rawDate = m.value().replace(/(\d{4}):(\d\d):(\d\d) /,"$1-$2-$3T");
// OPTIONAL (remove comments!): set record's creation date to date of image.
        // r.creationDate = new Date(rawDate);
      }
    })
    IE.close(image, {saving: 'no'});
  })
})()

This works for some image data (notably the creation date), but not for all EXIF data.

These solutions rely on external libraries that are not easy to import into JXA scripts. It should be possible to use a pure JXA solution based on the NSImage framework, but I don’t have the time to investigate that right now.

As you said, an alternative might be to script GraphicsConverter (if that’s already installed) or simply shell-script exiftool.

3 Likes

Thanks for adding your expertise Christian, and especially for pointing out (once again) the subtle difference between JS and JXA.

While we generally don’t suggest dependencies, their installation and use is up to the individual. So in this case, I’d agree that the venerable old exiftool would prove useful to @Herb.

2 Likes

It actually is possible, and I posted sample code in a new thread. This code can potentially get all EXIF data, which is a lot more than Image Events are willing to deliver.

2 Likes

You missed the important point:
If relevant metadata of a file are not directly accessible by DT, you cannot filter, sort or organise the files. And this is the key value of DT for me, that I can dump “all my life” into DT und will be able to find easily the information later again.

Hello Blanc, thank your for your suggestions. It makes me a bad conscious, since I am not fluent in scripting. I am sure that others will be able to make use of your thoughts.

Thank you for suggesting EXIFTOOL. Currently I retrieve the JPG metadata with GraphicConverter, which is my macOS standard app. It offers a window for the metadata.
To use the EXIFTOOL requires extra steps, like using the open with menu, etc.
This reminds me on one convenient feature request:
The ability to define an alternative app to open a file.
My everyday experience ist that I open my PDFs with either PDFexpert or with Preview.
It would be great if DT would over to open a secondary app by the use of the ALT key.

I didn’t miss it. I think you may have misunderstood what I said. I’ll say it a different way.

Put as much stuff into DEVONthink as you want. As long as that stuff is “searchable” or organised into real or virtual “groups”, you will be able to find it. How “easily”? Up to you I guess. And, you don’t have to use DEVONthink built-in features to view/edit/handle everything, e.g. store your Pages/Word documents in DEVONthink, but use Pages/Word to work with them. The “ecosystem” is Apple’s Mac “ecosystem” and is there to be used. People here have even kindly given you tips on you can use that ecosystem to “bend DEVONthink to your will”.

Most experienced users of DEVONthink recommend not putting *everything" i.e. “all my life” into DEVONthink. No reason for you to follow that recommendation if that not what you want, though.

1 Like

Which metadata do you actually need to be available in DT (and do you use the Pro version of DT)?

In addition to what @rmschne correctly remarked about „dumping all your life“ into DT: Apple makes it (deliberately?) difficult to retrieve all metadata from images programmatically.
For example, the code I posted (not blanc, btw), will not retrieve the camera maker and model. The framework function is apparently borken, and for a long time already.

So DT would have to include a fully fledged EXIF (and IPTC and XMP) library to get at all the image metadata. To replicate functions that are already available elsewhere. Not a sensible solution, I’m my mind.

So maybe it’s worth your while to take a step back and think about using an app that’s made to manage images instead.

1 Like

I am confused about what you want to tell me.
You talk about editing/viewing … – again, that is not my subject.
Furthermore, I don’t need anybody’s blessing what I put into DT.
And yes, this time you mentioned it, it is about search ability. Metadata DT can’t access, cannot be used for sorting or filtering. If I have a text file, the file creation or chance date is doing the trick. If it comes to JPG files the file system data are worthless. For my use case, the original record date and time of a picture is of interest.
In the past I used Apples Aperture app. It allowed to name the JPG with the record time and date. Then apple discontinue this powerful program and with Photos app, I have no measures to rename the file.
Don’t worry, I don’t store my 35000 photos in DT. Only photos belonging to projects in DT are exported to DT.
I appreciate the support on blanc and others. I did not start so far with tweaking DT with scripts and other programming. As a MSEE, I’d enough brain to master it. It is a conscious decision not to open this time consuming box. I already busy enough with many other subjects.

Oookay. Thought I was clear in my writing. Guess not. Good luck.

If that is all, then it is easily scriptable. Would it be preferable for the file to be given the original record date as the created date or as custom metadata?

1 Like

Hello Blanc,
Thank you for your kind offer. Here is my case:
I store all my projects in DT. Over time, there are a bunch of project related photos taken. They accumulate in the photos iCloud.
Every now and then, I export these photos to the DT group with the corresponding project. Then I purge them in the photos app, where I keep only my private photos.
So I have jpg files with names like the iPhone assigned it, e.g. IMG_7862.jpg.

What I need would the ability to sort and filter the jpg files after record time stamp.

If DT could access the EXIF data would be fine. But there is a workaround:
So a good workaround would be a script which I could apply on jpg files to extract the record time stamp and to store it in the creation time date of the file.
Then, I could sort and filter like I can do with e.g. text files and would be a happy camper.
Another work around would be a script which renames the jpg file name to represent the record time stamp, e.g. 2022-08-19-21-56-02 (just the time I typing this message).

@cgrunenberg (and @chrillek actually, but my JXA capabilities are insufficient to be able to quickly whip up a finished script) has already done most of the work; I‘ll see if I can add to it and provide you a working script. Do you use the export function in Photos, or do you drag and drop to DT?

It seems my statement “dumping my life into DT” is missunderstood. I talk about relevant information about project data, correspondence, procurement, financial data, tax data, etc. and also photos which related to projects and activities kept in DT.

I learnt and appreciate that DT can hold all bit and pieces of a project in one place, no matter what file format it is.
I don’t know what your use case with DT is, but I assume that you probably have also photos in your database.

I would prefer the file system creation date (I am not sure it this the correct name used in English - I use the german language version and Devonthink inspector names it with “Erstellt”
Creation date is properly shown in inspector, can be used for sorting and filtering. That is perfect.

With custom metadata, I have no experience if sorting and filtering works.

Maybe I’m comming in late, if I haven’ overlooked, about how many photos you are tallking about?
My foto library is about 2.5 TB (more than 200 k photos) and located on a dedicated hard drive. There is really good DAM software for photographers on the market, e.g. Photo Supreme, Photo Mechanic, iMatch… A very good freeware is XnView MP. All these have great capabilities and can read, display and modify exif data, filter photos by exif values, keyword management, color management and much more.
I love DT3, but I will never try managing my photo with it (I use photo supreme).

Probably it helps to take a look in this direction.

Edit: ups - I didn’t get that you use Apple Photos. Unfortunately these programm do not work with Apple Photos

1 Like