# Note Taking - "Note on Source" script?

**URL:** https://discourse.devontechnologies.com/t/note-taking-note-on-source-script/53765
**Category:** DEVONthink
**Created:** [February 18, 2020, 10:57pm UTC](https://discourse.devontechnologies.com/t/note-taking-note-on-source-script/53765 "2020-02-18T22:57:57Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)
#### Post date: [February 19, 2020, 10:51am UTC](https://discourse.devontechnologies.com/t/note-taking-note-on-source-script/53765/9 "2020-02-19T10:51:25Z")

</div>

Ah, you have to change every occurence of `"com.devon-technologies.thinkpro2"` to `"DNtp"` (didn’t know the script uses script libraries).

Also the script you’ve posted has curly quotes `“ ” ` instead of straight ones and the annotations aren’t escaped, this `– Smart template `should be this `-- Smart template`. Script Debugger didn’t compile it, but it seems Script Editor does. Get a (free) copy of [Script Debugger](https://latenightsw.com) it’s very useful e.g. for such situations.

This compiles, but didn’t test the script itself:

```
-- Smart template adding a localized annotation for a shown document

-- Written by Eric Böhnisch-Volkmann, modified by Christian Grunenberg

-- © 2009 DEVONtechnologies, LLC

-- Modified by Konrad M. Lawson http://muninn.net/

-- K: Thanks to Eric and everyone on the DEVON team for creating this wonderful software and a rich set of scripts to learn from

-- The non-localized default name of the new quote

property pTemplateName : "Note"

property pAnnotationsGroup : "/Notes"

-- Format the date for the title of the note

set this_date to (the year of the (current date) as string) & "." & (the month of the (current date) as number as string) & "." & (the day of the (current date) as string) & " " & the time string of the (current date)

-- 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

try
	
	tell application id "DNtp"
		
		-- If a document was frontmost when activating the smart template get its item link
		
		set theFrontmostDocument to content record
		
		set theFrontmostWindow to think window 1
		
		if (theFrontmostDocument is missing value) then error my helperLibrary's localizedString("No document shown. Please select a document, then try again.")
		
		set theFrontmostDocumentURL to ("x-devonthink-item://" & uuid of theFrontmostDocument) as string
		
		set theFrontmostDocumentName to name of theFrontmostDocument as string
		
		-- 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
		
		-- Create the Notes group, if necessary
		
		-- set theAnnotationsGroupRecord to create location (my helperLibrary’s localizedString(pAnnotationsGroup))
		
		-- if theAnnotationsGroupRecord is missing value then error my helperLibrary’s localizedString("Could not create the ‘Notes’ group.")
		
		-- Import the predefined document
		
		set theTemplateFiles to helperLibrary's pathToLocalizedResources() & ((my helperLibrary's localizedString(pTemplateName) & ".rtf") as string)
		
		set theRecord to import theTemplateFiles placeholders {|%documentName%|:theFrontmostDocumentName, |%documentLink%|:{|URL|:theFrontmostDocumentURL, |name|:my helperLibrary's localizedString("Source")}} to current group
		
		-- Before this was imported to theAnnotationsGroupRecord but now to the current group
		
		-- Adjust name of the document
		
		set the name of theRecord to this_date & ": " & theFrontmostDocumentName
		
		-- Set the tags of the note to the tags of the original overview document.
		
		set the tags of theRecord to the tags of theFrontmostDocument
		
		-- Finally, add the note’s item link to the annotated document’s URL field if possible
		
		-- K: I don’t understand what this is doing other than creating a link reference for only the first note that is added.
		
		-- If there is more than one note on a source, it still links to the first note so this doesn’t seem very useful:
		
		(*

if URL of theFrontmostDocument ≠ "" then

set theComment to comment of theFrontmostDocument

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

else

set URL of theFrontmostDocument to ("x-devonthink-item://" & uuid of theRecord) as string

end if

*)
		
		-- K: I would prefer for a tab to be opened but I can’t figure out how to get the tab to be displayed
		
		-- in front of the currently displaying record, rather than behind it
		
		-- 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
```

---

_[View the full topic](https://discourse.devontechnologies.com/t/note-taking-note-on-source-script/53765)._
