Reliable type checking and file paths


I’d just like to say to start that I’ve just purchased DEVONthink pro after playing with it for about two weeks. I think it’s a spectacular piece of software: you guys have really done a great job.

I hate to make my first post on these forums a scripting question, but I’ve been hammering at this script for a couple hours and I’m a little stuck. I have never done any applescripting before, so I apologize if these questions are a bit on the common-sense side. What I am attempting to write is a script to generate a LaTeX file from a group in DT. I have it working in a rough way I would like it to for rtf/txt and groups, but I’ve hit a few small snags and I’m curious if anyone might have some suggestions.

My first problem is that I’m having some troulbe reliably detecting the type of a record. The following code:

		set recordType to the type of theRecord as string
		display alert "DEVONthink Pro" message recordType

The above seems to produce different results when run from the Script Editor than it does when run from within the scripts menu in DT pro. If it run it from the editor, I get results like “group” or “txt”, if I run it from the scripts menu I get a crazy pointer type like “<<constant ****DTgr>>” or “<<constant ****pict>>”. I’m guessing this is a context problem, so I assume I’m just doing something stupid here… does anyone happen to have a suggestion on how to reliably check the type of a record object? Should a create a new record object, set its type and use that as a baseline?

My second problem is in dealing with records of picture type. All I need is to get the path to the image stored in DT, and then write a \includegraphics{…} to my LaTeX file. At first, I thought the path property of the record might work, but it seems to me that would only work if the file was still at the location it was at when imported into the system. I tried using export to send the file to a temporary location and then clean it up after the script finishes, but DT doesn’t seem to like exporting picture files (am I wrong here? Nothing was happening, but the same code works for txt and rtf.) Is there some way I can use the location property to get at the data inside the database? Or should I write an export routine that creates a new file with the finder, and sets its content to data?

Anyway, I’m going to mull over this for a while, any suggestions or tips would be greatly appreciated :slight_smile:



The first problem is easy: you need to wrap the "Using terms from ‘devonthink pro’…“end using terms from” construct around your code blocks. That will make sure the applescript editor knows how to present data and verb types from dtpro.

The second one is a little more complicated. You could make the decision to index pictures and rather than import them into the database. This way the paths would be static, and get location will do what you want as long as you don’t move the images around in dt. (DTPro 1.1 will make it significantly to deal with keeping externally linked files up-to-date)

With the current version of dtpro, I think it makes more sense to just export the file as you need it via applescript. The export command should work fine, as long as you pass it a posix path as its destination. It seems to work for me, at any rate. Please show the code that is failing to export…




thank you for the suggestions, I’ll definitely give these a shot next time I get a chance.