Delete Country, Administrative Area, Postal Code, Locality?

Hi all,

I started using DT3 on a new MacBook last month. However, when setting up, I’d forgotten to switch off Location Services for DT3 for several weeks, so quite a few of my documents now have Country, Administrative Area, Postal Code, and Locality data. I can’t figure out a way to delete them.

I would like to delete this because I would prefer my documents not to carry such identifying data about my location, especially since many are in non-encrypted databases.

I initially thought manually deleting the Inspector’s geolocation data should be enough. However, I realised that the Country, Administrative Area, Postal Code, and Locality fields still retain their data even with the Geolocation field empty.

I looked through the forums and found this:

I have zero scripting know-how but decided to bite the bullet and try, so I read the chapter on Automation in the documentation (v.3.9.2) and figured I should be able to plug @BLUEFROG’s above script into a smart rule.

So I created a test database, duplicated one of the relevant documents in there (as shown in the above screenshot), and set up the following smart rule:

I then selected Apply Rule from the dropdown menu:

But the Country, Administrative Area, Postal Code, and Locality data remain in my test document. This makes sense in hindsight as it’s probably written to delete the geolocation data, which I had already done so.

I then thought maybe I could modify the script to set these fields to "" and opened up the DT Library in Script Editor but could not find anything for Country, Administrative Area, Postal Code, and Locality.

I couldn’t find anything else in the forums when I searched for deleting Country, Administrative Area, Postal Code, and Locality, so I do appreciate any advice! Thanks in advance.

That’s really intriguing. First off, I suppose that you’re right: The geo information (country, county etc) is set once when the coordinates are determined. If you change the coordinates or remove them, the geo information stays. It’s probably like with EXIF/ICMP data where the coordinates are independent from the textual geo information.

As to the scripting dictionary: Yes, there’s no mention of country etc there. Nor is it in the documentation, unfortunately. My best guess is that DT uses internal metadata. The following script will display the names of the metadata for a selected record. It’s written in JavaScript. You can run it from Script Editor when you change the language selector in its upper left to “JavaScript”

(() => {
  const records = Application("DEVONthink 3").selectedRecords();
  records.forEach(r => {
    Object.keys(r.metaData()).forEach(k => console.log(k));

When you run that on one of your records, what does it tell you? If there’s nothing related to your problem (I can’t test that because I never had localization turned on), you could try the custom metadata:

(() => {
  const records = Application("DEVONthink 3").selectedRecords();
  records.forEach(r => {
    Object.keys(r.customMetaData()).forEach(k => console.log(k));

(or you could combine both scripts into one, of course).
Does that tell you anything? If so, it’s no biggy to remove the metadata (custom or otherwise).

If not, @BLUEFROG might have an idea…

Only longitude, latitude & altitude are stored and can be changed by scripts.

Ah haha, complete script novice here, so where scripting is required, step-by-step guidance is appreciated, without which there are likely steps that may be obvious for a veteran that would be completely opaque for one such as myself. :sweat_smile:

So in any case I decided to give it a shot. I copied and pasted both of your scripts as-is into Script Editor and clicked Run the Script and here are the results:

I thought maybe I could save the scripts to a file and then run it from a DT smart rule as an external file but alas, my assumption was wrong.

So I wondered about plugging your scripts into the smart rule itself, but it is far less obvious than AppleScript where to put what:

I did something earlier (with your first script) which did result in something showing up in DT’s log but not sure if that’s meaningful information or just a notification that I did it wrong lol.

Turn on the debugging pane in Script Editor by clicking on the three horizontal bars at the bottom. Then you can follow the execution of the script and see the output of console.log in the messages pane. I agree, the undefined “Result” is most unhelpful.

Putting the scripts in a smart rule is not sensible, as all they do is write stuff to the console. And there is no console in DT.

Nothing is “obvious” about that, in any language. In AS, you have to use a “handler” (Apple’s name for a subroutine)

on performsmartrule

and in JavaScript, it’s a “function” (JavaScript’s name for functions and subroutines):

function performsmartrule(records) {

Both languages have their rules. Those of JavaScript are formalized in a grammar, those of AppleScript are written down somewhere and have never been formalized in a grammar. Which of that is more “obvious”, I don’t know.

Ha that’s a relief to know it’s not just me then :stuck_out_tongue_closed_eyes:

I appreciate the step-by-step explanation. Not sure if this is any more helpful, but nothing else shows up in the console when I view events (replies look pretty much the same):

You didn’t select any records before running the script, did you? And switch to the Message pane, please, to see the output

Sure thing, so just to be safe, I quit and restarted DT3 and Script Editor. This is how DT3 looks like just prior to running the scripts, with nothing selected:

Then I ran the scripts again. Interestingly, I note that the first time I click Run the Script, nothing showed up in the console for either. Then when I clicked Run the Script the second time, I got the same results as before. Here are the Message pane outputs:

And just in case I was supposed to select a document, I selected my test document as so:

And when I clicked Run the Script again for both scripts:

First script:

Second script:

Apologies if that’s one too many screenshots lol, I just want to be sure to cover all bases.

Hm. I wrote two times that the script runs on selected records. How was that unclear? And then you select a record that doesn’t have any metadata.
Agreed, the script doesn’t do any error checking. But it would certainly be more helpful to select a record that does display your problem – rather than posting a bunch of screenshots :wink:

Just for the record, here’s a script with error checking. But it is utterly useless to run that on a record that doesn’t show your problem

(() => {
  const records = Application("DEVONthink 3").selectedRecords();
  records.forEach(r => {
    console.log(`${} >>`);
	const md = r.metaData();
	if (md) {
       Object.keys(md).forEach(k => console.log(k));
	 } else {
	   console.log(`No metadata in record`);

This should theoretically be sufficient to reset the geolocation of all items in all opened databases:

tell application id "DNtp"
	set theRecords to search "md_locality!="
	repeat with theRecord in theRecords
		tell theRecord
			set {altitude, latitude, longitude} to {0, 0, 0}
		end tell
	end repeat
end tell

However, due to a bug the cached information (country, zip code, locality, area) isn’t reset. The next release will fix this.


So, when the geolocation data is set, DT also sets these fields (county, zip etc) internally. But they are inaccessible to scripting, right? Can one search for them or otherwise use them?

Ah but you see, perhaps it wasn’t unclear to you because you are very familiar with what to do and what happens, but it may be unclear to someone who had no idea how the scripts offered were going to affect DT3 from within Script Editor. :wink:

I selected a record that has Country, Administrative Area, Postal Code, and Locality data as shown in my screenshot above, which was, to me, a document with which I was experiencing problems i.e., a document without geolocation data but Country, Administrative Area, Postal Code, and Locality data still persisting. As those were my concerns, I naturally assumed that was what I was to test the scripts on.

I appreciate your time @chrillek; however, I suggest approaching helping others from an absolute beginner’s mindset, especially when the person has already pointed out they are such. It may help you better understand why others don’t seem to be able to follow your well-intentioned help and make for easier communication both ways.

@cgrunenberg Thanks for that! If I understand correctly, this is a script I can use as a smart rule, correct? And no worries, looking forward to the next release; many thanks for your help as always. :pray:t3:

Only via the search command like in the example but they’re not accessible.

Just so you know, IMHO, what you are seeking and using Scripts/Automation, are not really something for “beginners”. When getting into this complicated stuff, complications has to be embraced.

At one point in my long time using computers, I would be able to handle Applescript, I’ve noticed it’s not simple.

I overlooked that one. In that case, the error showed that there are no meta data. The last script I posted will log a message saying that.

As for the rest: there’s only so much I can do. Explicitly stating that a script runs on a selected record is not something I can make clearer.
If you’re afraid for your data (as you should be with an unknown script), use it on test data in a test database.

It should be sufficient to use this script once and to disable DEVONthink in System Settings > Privacy & Security > Location Services.

1 Like