Hi
I have been modifying the Annotations template and would like to know how to add the tag ‘annotation’ to the script (but not delete any tags it already has).
I have googled and looked around and sorry if I have missed it.
Thanks
Matt
Hi
I have been modifying the Annotations template and would like to know how to add the tag ‘annotation’ to the script (but not delete any tags it already has).
I have googled and looked around and sorry if I have missed it.
Thanks
Matt
A simple example would be (assuming the variable thisRecord is pointing to the record)…
set tags of thisRecord to (tags of thisRecord) & “annotation”
Great thank you.
No problem.
So two years later fresh install and I can no longer get this to work
Not sure what I am doing wrong. No errors it just doesnt add any tags…
-- Smart template adding a localized annotation for a shown document
-- Written by Eric Böhnisch-Volkmann, modified by Christian Grunenberg
-- © 2009—2016 DEVONtechnologies, LLC
-- The non-localized default name of the new quote
property pTemplateName : "Annotation"
property pSmartGroup : "Annotations"
-- Import helper library
tell application "Finder" to set pathToAdditions to ((path to application id "DNtp" as string) & "Contents:Resources:Template Script Additions.scpt") as alias
set helperLibrary to load script pathToAdditions
set pathToLocalizedResources to my helperLibrary's pathToLocalizedResources()
try
tell application id "DNtp"
-- If a document was frontmost when activating the smart template get its item link
if exists (content record) then
set theFrontmostDocument to content record
else if (count of the selection) is 1 then
set theFrontmostDocument to item 1 of ((the selection) as list)
else
error my helperLibrary's localizedString("No document shown. Please select a document, then try again.")
end if
set theFrontmostWindow to think window 1
set theFrontmostDocumentURL to ("x-devonthink-item://" & uuid of theFrontmostDocument) as string
set theFrontmostDocumentName to name of theFrontmostDocument as string
-- Add smart group if necessary
set pSmartGroupLocalized to my helperLibrary's localizedString(pSmartGroup)
set pSmartGroupLocalizedPath to ("/" & pSmartGroupLocalized) as string
if not (exists record at pSmartGroupLocalizedPath) then
set theSmartGroupFile to my helperLibrary's pathToLocalizedResources & pSmartGroup
set theSmartGroupRecord to import theSmartGroupFile to root of current database
if theSmartGroupRecord is not missing value then
set the name of theSmartGroupRecord to pSmartGroupLocalized
end if
end if
-- Check if an annotation already exists
-- If yes, simply open the annotation and return
if URL of theFrontmostDocument starts with "x-devonthink-item://" then
set theAnnotationURL to the URL of theFrontmostDocument
set theAnnotationUUID to (characters 21 thru -1 of theAnnotationURL) as string
set theOldRecord to (get record with uuid theAnnotationUUID)
if theOldRecord is not missing value then
-- Test if it is in the trash
set inTrash to true
repeat with aParent in parents of theOldRecord
if (id of aParent) is not equal to (id of trash group of current database) then
set inTrash to false
end if
end repeat
if not inTrash then
open window for record theOldRecord
return
end if
end if
end if
-- Add page parameter if a current page attribute is available for this record
if the current page of theFrontmostWindow ≠ -1 then
set theFrontmostDocumentURL to theFrontmostDocumentURL & "?page=" & ((the current page of theFrontmostWindow) as string)
end if
-- Import the predefined document
set theTemplateFiles to my helperLibrary's pathToLocalizedResources & ((my helperLibrary's localizedString(pTemplateName) & ".rtf") as string)
set theParents to parents of theFrontmostDocument
set theFirstParent to item 1 of theParents
set theRecord to import theTemplateFiles placeholders {|%documentName%|:theFrontmostDocumentName, |%documentLink%|:{|URL|:theFrontmostDocumentURL, |name|:my helperLibrary's localizedString("Click here to view annotated document")}} to theFirstParent
set tags of theRecord to (tags of theFrontmostDocument) & "annotation"
-- Replicate it to the other parents if necessary
if (count of theParents) > 1 then
repeat with aParent in (items 2 through -1) of theParents
replicate record theRecord to aParent
end repeat
end if
-- Adjust name of the document
set the name of theRecord to (theFrontmostDocumentName & " (" & my helperLibrary's localizedString(pTemplateName) & ")")
-- Finally, add the note's item link to the annotated document's URL field if possible
if type of theFrontmostDocument is not bookmark and type of theFrontmostDocument is not feed then
if URL of theFrontmostDocument ≠ "" then
set theComment to comment of theFrontmostDocument
set tags of theFrontmostDocument to (tags of theFrontmostDocument) & "annotation"
if theComment ≠ "" then set theComment to theComment & return
set theComment to theComment & my helperLibrary's localizedString("Original URL") & ": " & (URL of theFrontmostDocument)
set comment of theFrontmostDocument to theComment
end if
set URL of theFrontmostDocument to ("x-devonthink-item://" & uuid of theRecord) as string
end if
set tags of theRecord to (tags of theRecord) & "annotation"
-- open tab for record theRecord in think window 1
open window for record theRecord
end tell
on error errMsg number errNum
display alert (localized string "An error occured when adding the annotation.") message errMsg as warning
end try