Extracting Photo Metadata for DT3 file

I’m looking for good way of creating a simple DT3 document that contains a photo, along with the text of certain fields of its Metadata. I’d probably be doing a couple of hundred of these. I’m thinking RTF would work, but I don’t know how to get the file field contents within DT3. Right now the fields include the Title, Comment, DateCreated, Location and Description fields.

Can you post a screen capture of a dummy document?

Concept Attached. Screenshot of DT3 Viewer window. I did notice that the image goes to full size instead of being scaled to fit margins - but that’s another issue.

See Preferences > Editing

Sorry for the confusion. I’m OK in the DT3 editor. Editing>Scale Image Attachments is checked. The image goes to full size in the .rtfd when I double click the record in DT3.

Are you entering the geolocation as custom metadata?

No, I’m not using custom metadata. For the dummy document I did cut and paste from OSx info of the file, see attached, other than TimeDateOriginal which I copied from the file Metadata in GIMP. I’m trying to capitalize on all of the work I’ve done previously with my photos.

I did see Geolocation when viewing my photo in Apple Photos. And I noticed that when I clicked Data>Tags>Convert Geolocation to tags, the geolocation showed up in the tags for the file So, I believe DT3 has access to all of the information, just a matter of how to collect it an present it in a single DT3 record.

In theory, it should be possible to extract the data with JavaScript/AppleScript from the image using the Image Event framework. In practice, Image Event’s EXIF/IPTC support is abysmal (in fact, it is mostly absent – contrary to what the scripting dictionary implies. But what else is new).

It is however possible using the Objective-C bridge and the NSMetadataItem class. A very simplistic snippet in JavaScript follows below. It is modelled after the sample AppleScript code found here:


(() => {
  /* Adjust this to suit your needs */
  const pathToImage = '/Users/ck/Pictures/Arbeitsverzeichnis/Fertig/Hubbrücke.jpg';
  const metadata = $.NSMetadataItem.alloc.initWithURL($.NSURL.fileURLWithPath($(pathToImage)));
  const atts = metadata.attributes.js;
  atts.forEach(a => {
    const value = metadata.valueForAttribute(a);
    console.log(`${a.js}: ${value.js}`);

You can run that in script editor as it is (of course after having changed the pathToImage to an image you’re interested it. The script will then print all the available metadata to the editor’s Message tab.

That’s but a starting point. It should not be too difficult to combine this with the image itself into a markdown document.

Getting the location, though, is a completely different thing. Though Apple provides reverse geocoding in its Core Loction framework, I wouldn’t know how to access that from JavaScript (for purely technical reasons). It might be possible in AppleScript, but that would be for @pete31 to judge. Also, reverse geocoding with Apple’s infrastructure is rate-limited, so attempts might fail at any time.

1 Like

Thanks so much. I appreciate your help.

My best suggestion is that you look to create your RTF documents (with text and your photos) using Python.

The “Pillow” library provides the capability to extract photo metadata. See https://www.thepythoncode.com/article/extracting-image-metadata-in-python for an explanation. Another article perhaps of use is How to extract GPS coordinates from Images in Python | by Abdishakur | Spatial Data Science | Medium

There are many libraries available to produce any sort of document, e.g. RTF, PDF, DOCX, and of course HTML and always popular Markdown (but the latter do not include the photo inside side the document file).

Then store the documents you create in DEVONthink.

1 Like

While that’s true in general, you can make them include a thumbnail or the original image (with certain drawbacks, of course).

1 Like

Didn’t try but this should work.

While exiftool is a brilliant utility, it wouldn’t be my first choice in this case. Since one has to write a program (Python) or a script (AppleScript/JavaScript) anyway, going for an API as @rmschne suggested (or NSMetadata as I proposed) would be the more natural choice: no external process to start, no worries with quoting/escaping parameters and no trouble with extracting the relevant values from the string’y output.

Just simple API calls returning what I’ve wants.

1 Like

Temporarily importing/indexing the image into a database (e.g. the global inbox) and using the values of the meta data property might be an option too but I’m not sure whether it will include all the desired fields.

If this meta data property is what Image Events calls MetadataTags it will be missing most EXIF and all IPTC data.

However, if meta data is coming from NSMetadata, the stuff should be there (or at least most of it)

Neither MetadataTags nor NSMetadata. The second option requires a valid and complete Spotlight index but Spotlight doesn’t index e.g. network volumes. And DEVONthink doesn’t use Spotlight at all, it’s not even enabled on all my computers :slight_smile:

Anyway, this property is an indexed, unified representation of certain document metadata/properties (of e.g. RTF(D), PDF, images, HTML, emails etc.). In case of images EXIF, IPTC, RAW, TIFF, PNG and GPS data is used (but not all available metadata).

1 Like

I tried the previous suggestion for AppleScript, but it wouldn’t accept ObjC.import. Since I don’t know anything about Python or AppleScript I gave up. I’d seen other suggestions for ExifEditor so I gave it a try and using terminal got it to extract all data on one of my files. All the fields I was looking for were in that output except Geolocation (but coordinates were there). So I looked down the command line examples and found this one - figured I could use it to collect the metadata on all of the image files in my directory.

exiftool -common dir

Print common meta information for all images in dir.

While that sounded like a good idea, I could not get it to recognize the path to dir. Don’t know if was my syntax, the two word directories along the path or that I’d not given permission for ExifEditor to access the directory. Then I realized that even if I did get it to work, I’d have to figure out how to get the field results back into DT3. I can already access the file info and use copy and paste.

I do appreciate the feedback from the community. And I’ve learned a lot, but mainly that if I’m to be able to communicate properly at this level I will need to invest in learning the basics of ExifEditor, AppleScript and Python. While those are worthy goals, I need to stay focused on creating my content. And DT3 is my best overall solution for managing my information. I’m going to spend some time working with DT3’s Custom Metadata feature to see what it might have to offer.

If you could post the code that you’ve actually used we could probably help.

Well, that was not AppleScript but JavaScript. And the code runs just fine in Script Editor if you select JavaScript as language (upper left) instead of AppleScript.

Regardless of that: I’d suggest to use a roll geared towards image management instead of bending DT. That’s what dedicated tools are for.