I’ve been following the discussion over at this thread:
about adding a CSS header to markdown files. I’ve managed to get it working for new files and now I’m looking to add it retrospectively to old files – that will be enough for me, although it wouldn’t meet the needs of the OP in that thread.
I’ve cobbled together the following short basic script to do this: it tests the file to see it already has a CSS header and if not adds a DTP link to the CSS document I keep in the database.
It seems to work OK when I’ve tested it, but before I apply it to four thousand files or so, I would be grateful if somebody who knows what they’re doing could have a quick look and tell me if there is anything in it which is bad practice or could cause problems.
tell application id "DNtp"
set theSelection to the selection
if theSelection is not {} then
set theCSS to "<link rel=\"stylesheet\" href=\"x-devonthink-item://C8B8E159-9653-4E7F-AE0F-1CD6F04246BE\">"
repeat with theRecord in theSelection
set theText to plain text of theRecord
if theText does not start with "<link rel=" then
set theText to theCSS & return & return & theText
else
set theText to theText
end if
set plain text of theRecord to theText
end repeat
end if
end tell
Secondly, the idea is to use a smart group to pick up all the Markdown files across my databases, using Kind is Plain Text – which of course picks up .txt files as well as .md.
I could just sort and select that way, but is there any way in a Smart Group or Script of differentiating between Plain Text and Markdown files in the database?
Many thanks for your help.