How to import notes containing Excel and PDF from Evernote and display them inline

OK, since you baited me… I hacked something together in JXA-ObjC that takes the path of a DT record, generates a Quicklook preview from it, converts that into a Base64 coded data URL and could write the latter to another or the same DT record.

ObjC.import("Cocoa");
ObjC.import("Foundation");
ObjC.import('CoreFoundation');
ObjC.import('QuickLook');
ObjC.import('AppKit');

const app = Application("DEVONthink 3");
const rec = app.getRecordWithUUID("some UUID")

const path = rec.path();
const pathURL = $.NSURL.fileURLWithPath(path);

const cgimageRef = $.QLThumbnailImageCreate($.kCFAllocatorDefault, pathURL, $.CGSizeMake(600,800), {});
const nsimage = $.NSImage.alloc.initWithCGImageSize(cgimageRef, $.NSZeroSize);
const newRep = $.NSBitmapImageRep.alloc.initWithCGImage(cgimageRef);
newRep.setSize(nsimage.size);
const pngData = newRep.representationUsingTypeProperties($.NSPNGFileType,{});
const b64 = 'data:image/png;base64,' + ObjC.unwrap(pngData.base64EncodedStringWithOptions(0));
/* b64 is a data URL 
you can insert it into an MD file like
![](b64)
*/

This is noting more than a proof of concept. It shows that you can add a preview of any file accessible to Quicklook as an image to a MD file. And I’m not even sure if everything in this script is even necessary.

If you should do that is a completely different question. My sample Numbers table generated a PNG of about 60 KB, so the Base64 encoded data URL is about 90K – of gibberish, just to have a nice picture. I’m not going down this road, since at the end lies madness. But if anybody else feels intrigued … be my guest.

2 Likes