I’m afraid my basic knowledge of AppleScript is letting me down again and I need some help. I’m back with my Day One journal entries imported into DT as individual markdown files. In Day One there are many links within entries to other entries in Day One. Of course, those are preserved in the DT markdown files as Day One links but, not satisfied with that, I had the idea of creating a custom metadata field for item links within DT. In other words, that field would contain the entry to which the Day One link links while still preserving the original Day One link in the imported entry. I should say that each individual markdown record in DT has a name like “Thursday 22 July 2021”.
I’ve not been particularly sophisticated about this so thought of highlighting an entry, inputting the relevant link date and having DT update the custom metadata field accordingly. (The custom metadata field is “link” set to “Item link”.)
I have, of course, fallen flat on my face.
set dAnswer to "01/07/2021"
set userEntry to display dialog ¬
"Enter the link date as DD/MM/YYYY" default answer dAnswer
set userDate to text returned of userEntry
set linkDate to date userDate
set wDay to weekday of linkDate
set dateDay to day of linkDate
set dateMonth to month of linkDate
set dateYear to year of linkDate
set theLink to wDay & " " & dateDay & " " & dateMonth & " " & dateYear & ".md"
try
tell application id "DNtp"
set myRecord to selected record
add custom meta data theLink for "link" to myRecord
end tell
on error errStr
display alert ("Error: " & errStr)
end try
Initially I had all of the code bar the first line within the try block - but then obtain an error on the line:
set linkDate to userDate
That, however, works perfectly well outside the try block but then, with the code as is, DT tells me “Invalid argument record”.
I’m not actually sure updating of the link field is even going to work but can’t yet get that far to test it. Some gentle guidance (even if merely indicating this is ridiculous and should be abandoned) would be welcome.
Stephen