Creating and Linking to a Record with Selected Text

Hello everyone,

I made a very simple little script that does something slightly different from some of the excellent annotation and note scripts. Its usefulness to me is best described with an example:

-As a historian I have lots of sources I’m taking notes on (which each have note files created by my Zotero to DevonThink applescript). There often appear historical personages in these works.
-I have a folder called “People” at the root of my database where I keep an individual file for each and every person I wish to keep some separate notes on.
-Instead of manually jumping over to my People folder and creating a new person file each time I come across someone worth keeping track of, I wrote a script that does the following:

  1. In some file I’m taking notes in, I select the text corresponding to the name of the person I wish to have a file for
  2. I run the script below via a command shortcut
  3. The script creates a new person file in the person folder with a name corresponding to the selected text. If such a file exists already, it does not create a duplicate.
  4. The selected text in my current note file will be linked to that newly created (or previously existing) file
  5. The person note file is opened as a tab

There are number of related tasks that I can think of that could probably be done with minor modifications to the script. In case anyone else might find this useful, the script is below, and thanks to everyone on this forum for all your wonderful help and sharing of code:

	tell application id "com.devon-technologies.thinkpro2"
		set personName to the selected text of think window 1
		set groupName to "/People"
		set theGroup to create location groupName in current database
		if not (exists record at groupName & "/" & personName) then
			set personRecord to create record with {name:personName, type:rtf, rich text:personName} in theGroup
			--display dialog ("Hello: " & URL of newRecord)
			set URL of the selected text of think window 1 to ("x-devonthink-item://" & uuid of personRecord)
		else -- There is already a person in the person group by that name so let us link to that
			set personRecord to (get record at groupName & "/" & personName)
			set URL of the selected text of think window 1 to ("x-devonthink-item://" & uuid of personRecord)
		end if
		open tab for record personRecord in think window 1
	end tell
end try

If I could create Smart groups via AppleScript I would love to take this up a notch:

  1. instead of creating a single note file for a person, create a group for the person in the Person root group.
  2. inside the group for the person, put a single rtf note file
  3. and a smart group which looks for anything tagged the person

Any chance Applescript support for creating smart groups is coming soon?

Many thanks again to Devon Tech for making such a scriptable app.

This is an excellent idea, and of course can easily be cloned to apply to other categories by changing “/People” to something else that the reader is targeting. Note that the “set URL…” command can, from v2.0.4, be shortcut by using the “reference url” property of a record.

Ah, great, thanks! -Konrad