Note Taking - "Note on Source" script?

Hi all -

I’ll start by admitting I struggle with change. And never more so than with technology : )

I do historical work. At bottom, my DevonThink workflow was built around this “Note on Source” script from Konrad Lawson. The workflow basically involves (1) creating a source card for each discrete historical source, and then (2) running the “Note on Source” script to create a notecard that’s linked to that source card–allowing the note card to be replicated, duplicated etc., and organized by topic while still linking back to the original source.

I installed Lawson’s script in DevonThink 3, but it doesn’t work. That is, when I run it, nothing happens. Trying to figure out if there was an alternative solution, I of course dove into the forums. The closest I came was this thread and it honestly blew my mind with the technical detail.

Can anyone help me figure out if there’s some embedded solution that will approximate the Lawson script? (The “Annotations” feature seems to serve a different purpose.) Or, even better, help me figure out how to get the Lawson “Note on Source” script to work??

Many thanks, and my apologies for this incredibly nitty gritty and probably totally idiosyncratic question

-Michigan User

I just downloaded and opened it in Script Debugger, result:

AppleScript failed to retrieve the script’s source code.

Not sure, but it seems there’s something wrong with the script (at least over here)

1 Like

Thanks very much for this reply – I really appreciate it. And that makes sense, given how it’s behaving!

But what doesn’t make sense is that the script worked perfectly (for years, even!) with DevonThink 2. Obviously I’m not hoping for a debugging per new code requirements, but . . . is it possible there’s some obvious difference with how DT3 processes scripts vs DT2? Because it’s literally the same script I’ve used for years…

As far as I know the only difference could be the “tell application” part.

tell application id "DNtp"

should work with DEVONthink 2 and DEVONthink 3, but some scripts used something like

tell application "DEVONthink Pro"

and these scripts won’t work in DEVONthink 3.

If you’ve used the script for years maybe changing the tell part will fix it

1 Like

Thinking outside the box a bit

Are you sure you want to use this script with DT3 even if it works?

Are you familiar with the Annotations Inspector - and the related Annotations file it creates automatically, which can be replicated, duplicated, etc.?

I think a much better solution exists in DT3 than you are used to using.

1 Like

The Annotations Inspector is SO TEMPTING!! But (so far as I can tell) it only lets you create one Annotations file per underlying document. My needs are more complicated. Let’s say I’m working with the Declaration of Independence. Maybe I want the following notecards on it:

  1. “Complaints against the King.”
    [various quotes emphasizing specific complaints against the King]
  2. “Concept of Human Rights”
    [various quotes on conception of human rights, and my own thoughts on how they connect to larger developments in political theory at the time]
  3. “Jefferson’s characteristic style”
    [various quotes showing classic Jeffersonian turns of phrase, focused on the rhetoric of the document rather than on the substance]

Those are three very different “notecard” documents, and I’d like to be able to organize each in a very different part of my working DevonThink outline. But I’d like them all to link back to the same underlying source document. Unless I’m missing something, I don’t think that the Annotation Inspector lets me create multiple distinct documents suitable for that kind of “short chunk” sorting across multiple folders. Rather it will leave me with one (typically bulky) annotation file for any document.

Am I missing something? Because you are right! The “Annotation Inspector” feature seems SO TEMPTING, but . . . just not quite right.

You are very kind to think about this and suggest a possible fix. Thank you!

I did find this in the script below: tell application id “com.devon-technologies.thinkpro2” . I changed the stuff inside the quotes to “DNtp” and saved it . . . but no luck : (

-- 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 "com.devon-technologies.thinkpro2" as string) & "Contents:Resources:Template Script Additions.scpt") as alias

set helperLibrary to load script pathToAdditions

try

tell application id "com.devon-technologies.thinkpro2"

-- If a document was frontmost when activating the smart template get its item link

set theFrontmostDocument to «class DTdr»

set theFrontmostWindow to «class thwi» 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://" & «class 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 «class DTpe» of theFrontmostWindow ≠ -1 then

set theFrontmostDocumentURL to theFrontmostDocumentURL & "?page=" & ((the «class DTpe» 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 «event DTpacd01» theTemplateFiles given «class DTph»:{|%documentName%|:theFrontmostDocumentName, |%documentLink%|:{|URL|:theFrontmostDocumentURL, |name|:my helperLibrary's localizedString("Source")}}, «class DTto»:«class DTcg»

-- 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 «class tags» of theRecord to the «class 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

«event DTpacd75» given «class DTrc»: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

Would it work for you to use the Hashtags to Tag feature inside an Annotation and create tags to name your notecards?

(Related question/issue here: "Hashtags to Tags" with Spaces in the Tag Name )

1 Like

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

You are so kind to help me figure this out. I’ve worked in the edits you suggested and … it works!!! I don’t understand why going to DT3 changed the scripts functionality, but mine is not to reason why : )

Really really appreciate your taking the time to help me work this through. Incredibly generous and kind. Thank you.

“com.devon-technologies.thinkpro2”

This was the old bundle id for DEVONthink 2.x (noting the thinkpro2). This is why we have long advocated using the application id DNtp, since that was used in 2.x and is also the same for DEVONthink 3.

1 Like