im interested for the sake of compatibility and additional minor backup method to copy my devonthink tags for my many markdown files to the first line of the markdown file (based on the common syntax for tags) ie
tag: #tag1, #tag2
# note 1
anyone done something like this or has any idea how to achieve this?
A simple script to insert the tags could look like this:
tell application id "DNtp"
repeat with theRecord in (selection as list)
if type of theRecord is markdown then
set theText to plain text of theRecord
set theTags to ""
set theTagList to tags of theRecord
if (count of theTagList) is greater than 0 then
repeat with theTag in theTagList
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & theTag
end repeat
set theText to "tag: " & theTags & return & return & theText
set plain text of theRecord to theText
end if
end if
end repeat
end tell
Small question (and please feel free to ignore this if its to much work), but can the script be adjusted to not execute if the tags: line exists?
the rationale is that i run this every week on files, and if the script has been run already on a .md file it adds another tags: line
thx again, ive only been using devonthink for a few months but you and @BLUEFROG have the best support any company i know of hasā¦make using devonthink even more fun!
ive been using your script for a long time yet and its my #1 used script in Devonthink
was wondering (as i have zero Applescript knowledge), if it would also be possible to add the current Devonthink rating as a tag while the script runs?
ie rating of ā ā ā will be tag: #ā ā ā or tags:3 etc
tell application id "DNtp"
repeat with theRecord in (selection as list)
if type of theRecord is markdown then
set theText to plain text of theRecord
if theText does not start with "tag:" then
set theTags to ""
set theTagList to tags of theRecord
repeat with theTag in theTagList
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & theTag
end repeat
set theRating to rating of theRecord
if theRating is not 0 then
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & (theRating as string)
end if
if theTags is not "" then
set theText to "tag: " & theTags & return & return & theText
set plain text of theRecord to theText
end if
end if
end if
end repeat
end tell
hope all is well. the above script i have been using has seemed to stopped working for meā¦dunno why
also i want to be able to āforceā it to work on the files (ie delete the previous first tags: line and replace with new updated tags) and also add as tags the MD files label (in addition to the ratings and tags).
Any chance you can help me with adding this? i tried this:
tell application id "DNtp"
repeat with theRecord in (selection as list)
if type of theRecord is markdown then
set theText to plain text of theRecord
if theText does not start with "tag:" then
set theTags to ""
set theTagList to tags of theRecord
repeat with theTag in theTagList
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & theTag
end repeat
set theRating to rating of theRecord
if theRating is not 0 then
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & (theRating as string) & "star"
end if
set theLabel to label of theRecord
if theLabel is not 0 then
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & (theRating as string) & "star" & (theLabel as string)
end if
if theTags is not "" then
set theText to "tag: " & theTags & return & return & theText
set plain text of theRecord to theText
end if
end if
end if
end repeat
end tell
but it didnāt run at all (but as i said in general the script stopped working)
also not i tried changing the rating from #3 to #star since some applications like obsidian donāt like numeric tags
Is there anything in DTās log?
And: Did you try running the script in the script editor? It is a lot more verbose than DT. In order to do so, copy & paste the script into a new script editor window, select a record in DT, open the message window (three lines at the bottom of script editor) and then click on the right pointing triangle in script editor. If an error occurs, it will be reported in the message window.
tell application id "DNtp"
repeat with theRecord in (selection as list)
if type of theRecord is markdown then
set theText to plain text of theRecord
if theText does not start with "tag:" then
set theTags to ""
set theTagList to tags of theRecord
repeat with theTag in theTagList
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & theTag
end repeat
set theRating to rating of theRecord
if theRating is not 0 then
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & (theRating as string)
end if
if theTags is not "" then
set theText to "tag: " & theTags & return & return & theText
set plain text of theRecord to theText
end if
end if
end if
end repeat
end tell
this is my modification
tell application id "DNtp"
repeat with theRecord in (selection as list)
if type of theRecord is markdown then
set theText to plain text of theRecord
if theText does not start with "tag:" then
set theTags to ""
set theTagList to tags of theRecord
repeat with theTag in theTagList
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & theTag
end repeat
set theRating to rating of theRecord
if theRating is not 0 then
if theTags is not "" then set theTags to theTags & ", "
set theTags to theTags & "#" & (theRating as string) & "star"
end if
if theTags is not "" then
set theText to "tag: " & theTags & return & return & theText
set plain text of theRecord to theText
end if
end if
end if
end repeat
end tell
I wanted to change it so that:
it always overrides the first tag line with the current state
hmm im sure it did work at some stage i followed he above script from @cgrunenberg and iirc it did run from the smart ruleā¦but im pretty clueless with scripts so i wouldnāt bet my life on it
so how do you suggest to proceed, run this externally?
It can never have worked like this from a smart rule. As a standalone script, why not.
You could just make a copy of a record for texting, select it and then run the script. Either from the menu after having it copied to a suitable location or from script editor.