Good morning all
first of all thanks for your super helpful comments! this inspired me to dive into Applescript (and to be honest coding in generalā¦) for the first time in my life and it feels like i had done some baby steps advancements
this is the current state of my script (spoilers: the code is probably horrific since i donāt really know what im doing: ))
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 starts with "tag:" then
set theText to do shell script "sed -e '1,1d' <<<" & quoted form of theText
else
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 & "#" & (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
so the key areas that still donāt work
i still cant get the script to overrun/delete the first line if it starts with tags:.
i tried using this if else statement but it dosent seem to do anything
if theText starts with "tag:" then
set theText to do shell script "sed -e '1,1d' <<<" & quoted form of theText
else
set theTags to ""
for the cables i only get a 0 - 7 index. i read in the Devonthink library and i cant find how to translate the number to an actual label (TODO, DONE 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 starts with "tag:" then
set theText to do shell script "sed -e '1,1d' <<<" & quoted form of theText
set theTags to ""
this for some reason runs the first time and creates the tags line but deletes everything else apart from the tags line the 2nd run . any clue how i screwed this up?
just an update in case anyone wants to use this, i spend hours (but had lots of fun!) based on the incredible generous help go the community here (thx @DTLow and @chrillek and @cgrunenberg)!
this is the final version i cam up with which seems to do what i want
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 theLabel to label of theRecord
set theRating to rating of theRecord
if theTags is not "" then
set theText to "---" & return & "tags: [" & theTags & "]" & return & "priority: " & theLabel & return & "rating: " & theRating & return & "---" & return & return & theText
set plain text of theRecord to theText
end if
end if
end if
end repeat
end tell
still have an issue of getting rid of pre existing tag lines but will open a separate thread for that
Just interested in the purpose behind this (copying tags)
Iām comfortable the backups already include tag info,
and impressed that DT includes tags/folders when exporting notes to OS files
I use a script to add the tags to the note title as keywords to provide context