OK, I think I got it. Your files are named “Weekday d Monthname y” in DT. They’re named something else in DO (or rather: there are no filenames there). You want to augment the custom meta data in DT so that all links to DO are shown as x-devonthink URLs in the “link” field (as a side node: That’s ok if you have only one link in a file, otherwise … well).
So you need the date of the DO note the dayone link is pointing to. As far as I can tell, this step can not be automatized. In fact, there’s hardly any automation support at all in DO: they offer a CLI with exactly one command, which is a bit poor. No scripting at all. Understandable, given that they want you to use their software, not extract your data from it and use it somewhere else (I tend to be opionated).
Now, DO stores its data in the file ~/Library/Group Containers/5U8NS4GX82.dayoneapp2/Data/Documents/DayOne.sqlite
. That is, surprise, a SQLite database. As such, it can be queried with a shell command like so
sqlite3 DayOne.sqlite 'select * from zentry where zuuid="E3470F309F7A425184D6A2F45E72302F"'
and it will utter something like this:
2|12|2|0|0|0|21|7|2021|1|0|0||1|||||||648511200|25.8850209712982|648649823.148132|648518400|268F3C7E-528E-49CD-8B7C-BDBC0C5B803B|MBP-ck|MacBookPro16,1|MacBook Pro|macOS|11.5|||10|1:2021:07|# Das war der 21\.7\.21
An dem auch nix passiert ist\.|||{"meta":{"version":1,"small-lines-removed":true,"created":{"platform":"com.bloombuilt.dayone-mac","version":1300}},"contents":[{"attributes":{"line":{"identifier":"46C5D5EE-4C51-4308-8746-6BB96187B87A","header":1}},"text":"Das war der 21.7.21\n"},{"text":"\nAn dem auch nix passiert ist."}]}||E3470F309F7A425184D6A2F45E72302F|||bplist00�
X$versionY$archiverT$topX$objects
So, the date is contained in this record (being 2021-7-21 in this case). So, simply doing this in the shell
sqlite3 DayOne.sqlite 'select zgregorianyear||"-"||zgregorianmonth||"-"||zgregorianday from zentry where zuuid="E3470F309F7A425184D6A2F45E72302F"'
will tell you this
2021-7-21
which seems is just what you need to look up your DT record. You could of course massage the SQL statement to return the name of this record, but given that it contains the weekday and the name of the month, that might be stretching it a bit.
Now, in JavaScript, I’d do this to get the date of this UUID:
let app = Application.currentApplication();
app.includeStandardAdditions = true;
let result = app.doShellScript(`sqlite3 "/Users/<yourname>/Library/Group Containers/5U8NS4GX82.dayoneapp2/Data/Documents/DayOne.sqlite" 'select zgregorianyear||"-"||zgregorianmonth||"-"||zgregorianday from zentry where zuuid="E3470F309F7A425184D6A2F45E72302F"'`);
console.log(result);
Replacing, of course, <yourname> with yourname without the pointy brackets. And this, finally, prints out “2001-7-21”, just as we want it to.
I would not want to figure out how that’s done in AppleScript with all the quoting and stuff, but I’m sure @BLUEFROG knows the answer to that.
So what you have to do is basically this:
- find the link to your DO entry in the DT record (in JS, I’d do
const match = record.plainText().match(/view\?entryId=(.*?\))/);
const uuid = match[1];
- feed that uuid into the shell command above
- run that command and save its output in a variable
- fool around with this variable to figure out the DT record’s name
- get its uuid, build the DT link and add it to custom meta data
In fact, I’d rather add it right after the original DO link in the DT record. So that it’s clickable too, and you can have more than one link Something like
[DT data](x-devonthinkurl://<uuid>)
Disclaimer: I only tested the shell command, and only with one record. All the rest is … well, untested. Also, DayOne may decide to change their database schema at any point in time, and that may break the shell or the sql command. But until then, it should work.