# Disabled scholar needs help with some scripting tasks

**URL:** <https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590>\
**Category:** Automation\
**Created:** [April 3, 2006, 5:37pm UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590 "2006-04-03T17:37:38Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![MeitnikScholar](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@MeitnikScholar](https://discourse.devontechnologies.com/u/MeitnikScholar)\
**Post date:** [April 3, 2006, 5:37pm UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/1 "2006-04-03T17:37:38Z")

</div>

Cool tool DevonThink for sure! (I am exploring a 30 day trail) However I need some help. Due to my disabilites (legally blind, limited typing range for fingers), I need some scripts to do the follow tasks:

1. Given a folder of text files (scanned books and articles) named: PrimarySources  
Given a example file named within that folder: mydoc.txt  
A. To import that folder of files creating named groups based on each file name.  
B. and to add within the created group two other files whose filename is keyed to each group name: mydoc, Comments and mydoc, Quotes  
So my created Groups would look like this:  
PrimarySources  
MyDoc  
MyDoc.txt  
MyDoc, Comments  
MyDoc, Quotes

2. Once I have those files into DevonThink, I would hilite and annotate passages as I read them. However, once read, I need to grab the hilited passages into another file with the source of where the passages came from.  
Given filename: 1927 Theories Imagination, Bundy  
Given a hilited passages:  
“kdjf kk fj dskfk lfdsfjk fj dksfj kfj”, blue  
“iue ioru mxn cm”, pink  
I would have this in the doc:

1927 Theories Imagination, Bundy  
blue  
“kdjf kk fj dskfk lfdsfjk fj dksfj kfj”

1927 Theories Imagination, Bundy  
pink  
“iue ioru mxn cm”

Here is something I scripted using Tex-edit with help from a friend to show a flavor what I need:

```auto
tell application "Tex-Edit Plus"
	activate
	set Temp to ""
	copy 0 to y
	set L to tab & return & space
	copy (characters 1 thru -5 of (name of window 1 as string)) to nuTemp -- get source name
	set n to count of style runs of window 1
	repeat with x from 1 to n
		if hilite color of style run x of window 1 ? none then -- test for hilite
			copy y + 1 to y -- get note number
			copy hilite color of style run x of window 1 as string to Hilt -- get hilite color name.
			copy style run x of window 1 to T -- get hilited passage
			set pl to every paragraph of T
			set C to count of paragraphs of T
			repeat with i from 1 to C
				set p to item i of pl as string
				if (length of p is not 0) then
					repeat with z from 1 to 3
						set d to character z of L as string
						repeat while p starts with d
							set p to characters 2 thru -1 of p as string
						end repeat
						repeat while p ends with d
							set p to characters 1 thru -2 of p as string
						end repeat
					end repeat
					set item i of pl to (tab & tab & "\"" & p & "\"") & return
				end if
			end repeat
			set item C of pl to characters 1 thru -2 of item C of pl
			set T to pl
			set Temp to Temp & " Note" & y & " Category: Unknown" & return
			set Temp to Temp & tab & "Source:" & (nuTemp) & return
			set Temp to Temp & tab & "HiliteColor:" & (Hilt) & return
			set Temp to Temp & tab & "Quote:" & return & T & return
			set Temp to Temp & tab & "Comments:" & return & tab & tab & "[]" & return & return
		end if
	end repeat
	set the clipboard to Temp
end tell

```

Thanks for the help. 🙂 I hope I can do my research in Devonthink to work smart than just hard with my disabilities.

Andrew

---

<div class="post-metadata">

**Author:** ![MeitnikScholar](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@MeitnikScholar](https://discourse.devontechnologies.com/u/MeitnikScholar)\
**Post date:** [April 13, 2006, 2:28pm UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/2 "2006-04-13T14:28:51Z")

</div>

[size=150]Hi, Is there anyone willing to help me make fuller and easier use of DevonThink to overcome my limitations? Do I need to rework my request, resubmit it differently somehow. I am not a master Applescripter. I am open to better ways how I can obtain some scripts to help. Thanks 🙂[/size]

---

<div class="post-metadata">

**Author:** ![Knight\_of\_Nee](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@Knight\_of\_Nee](https://discourse.devontechnologies.com/u/Knight_of_Nee)\
**Post date:** [April 14, 2006, 10:54pm UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/3 "2006-04-14T22:54:29Z")

</div>

> [@MeitnikScholar](#):
>
> [size=150]Hi, Is there anyone willing to help me make fuller and easier use of DevonThink to overcome my limitations? Do I need to rework my request, resubmit it differently somehow. I am not a master Applescripter. I am open to better ways how I can obtain some scripts to help. Thanks 🙂[/size]

Here’s the first order. This script will create the group and sub documents (blank RTF docs) with the appropriate names.

```auto
property folder_Path : missing value
tell application "Finder"
	try
		alias folder_Path
	on error
		set folder_Path to choose folder with prompt "Pick a folder to import..."
		set folder_Path to folder_Path as string
		set document_List to list folder folder_Path without invisibles
		
		tell application "DEVONthink Pro"
			try
				repeat with i from 1 to count document_List
					set theGroup to item i of document_List as text
					set newGroup to create location theGroup
					set new_Child to create record with {name:theGroup, type:rtf} in newGroup
					set new_Child to create record with {name:theGroup & ", Comments", type:rtf} in newGroup
					set new_Child to create record with {name:theGroup & ", Quotes", type:rtf} in newGroup
				end repeat
			end try
		end tell
	end try
end tell

```

---

<div class="post-metadata">

**Author:** ![Knight\_of\_Nee](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@Knight\_of\_Nee](https://discourse.devontechnologies.com/u/Knight_of_Nee)\
**Post date:** [April 14, 2006, 10:56pm UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/4 "2006-04-14T22:56:31Z")

</div>

I’m working on importing the contents of the documents as well. I should have that revision soon. I didn’t want you to think that people on this message board don’t help out new users. Some how I missed your post.

---

<div class="post-metadata">

**Author:** ![Knight\_of\_Nee](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@Knight\_of\_Nee](https://discourse.devontechnologies.com/u/Knight_of_Nee)\
**Post date:** [April 14, 2006, 11:43pm UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/5 "2006-04-14T23:43:47Z")

</div>

Ok, now it imports the file to each group. Do you want the “Comments” and “Quotes” files to be empty from the start?

```auto
property folder_Path : missing value
tell application "Finder"
	try
		alias folder_Path
	on error
		
		-- let's ask for the user to chose the folder they want
		set folder_Path to choose folder with prompt "Pick a folder to import..." as string
		
		-- get the list of files in the folder
		set document_List to list folder folder_Path without invisibles
		
		tell application "DEVONthink Pro"
			try
				repeat with i from 1 to count document_List
					
					-- use the name of each file to create a new group in Devonthink
					set theGroup to item i of document_List as text
					set newGroup to create location theGroup
					
					-- assemble the path to the document so we can import it
					set doc_Path to folder_Path & (item i of document_List) as string
					import doc_Path to newGroup
					set new_Child to create record with {name:theGroup & ", Comments", type:rtf} in newGroup
					set new_Child to create record with {name:theGroup & ", Quotes", type:rtf} in newGroup
				end repeat
			end try
		end tell
	end try
end tell

```

[/quote]

---

<div class="post-metadata">

**Author:** ![MeitnikScholar](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@MeitnikScholar](https://discourse.devontechnologies.com/u/MeitnikScholar)\
**Post date:** [April 15, 2006, 12:00am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/6 "2006-04-15T00:00:14Z")

</div>

[quote=“Knight of Nee”]

[quote=“MeitnikScholar”]  
[size=150]  
—Here’s the first order. This script will create the group and sub documents —(blank RTF docs) with the appropriate names.

[size=18]  
Very helpful. Bless you and thanks you!

Hopfully the next version will handle sub folders:

PrimarySources  
Articles  
Books  
SecondarySources  
Articles  
Books

Andrew[/size]

---

<div class="post-metadata">

**Author:** ![MeitnikScholar](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@MeitnikScholar](https://discourse.devontechnologies.com/u/MeitnikScholar)\
**Post date:** [April 15, 2006, 12:03am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/7 "2006-04-15T00:03:10Z")

</div>

> [@Knight of Nee](#):
>
> Ok, now it imports the file to each group. Do you want the “Comments” and “Quotes” files to be empty from the start?

Yes, as I read the texts I will be typing comments and when the hiliting code is working, I will put that stuff into the quotes file.

Again thanks, off to test the newer code.

Andrew

---

<div class="post-metadata">

**Author:** ![MeitnikScholar](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@MeitnikScholar](https://discourse.devontechnologies.com/u/MeitnikScholar)\
**Post date:** [April 15, 2006, 12:14am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/8 "2006-04-15T00:14:12Z")

</div>

> [@MeitnikScholar](#):
>
> > [@Knight of Nee](#):
> >
> > Ok, now it imports the file to each group.  
> > …  
> > [size=150]Again thanks, off to test the newer code.
> > 
> > Andrew

it works, 🙂 but all my docs are .txt not .rtf. can these be converted to .rtf once imported via applescript inside devonthink??

and the import is fast too!

andrew[/size]

---

<div class="post-metadata">

**Author:** ![Knight\_of\_Nee](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@Knight\_of\_Nee](https://discourse.devontechnologies.com/u/Knight_of_Nee)\
**Post date:** [April 15, 2006, 2:12am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/9 "2006-04-15T02:12:28Z")

</div>

> [@MeitnikScholar](#):
>
> > [@Knight of Nee](#):
> >
> > > [@MeitnikScholar](#):
> > >
> > > [size=150]  
> > > —Here’s the first order. This script will create the group and sub documents —(blank RTF docs) with the appropriate names.
> > > 
> > > [size=18]  
> > > Very helpful. Bless you and thanks you!
> > > 
> > > Hopfully the next version will handle sub folders:
> > > 
> > > PrimarySources  
> > > Articles  
> > > Books  
> > > SecondarySources  
> > > Articles  
> > > Books
> > > 
> > > Andrew[/size]

I’m a little confused. What is the directory structure of the folder you are importing from? How many subfolders do you have? Are they always titled the same? I assumed that you had a folder filed with text files that you wanted imported into Devonthink. If there are other folders within, then this script will definately NOT work correctly.

As for converting txt files to rtf, there should be no reason to do that, unless you absolutley do not want the ability to format the text. I would just leave them as an rtf document.

---

<div class="post-metadata">

**Author:** ![Knight\_of\_Nee](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@Knight\_of\_Nee](https://discourse.devontechnologies.com/u/Knight_of_Nee)\
**Post date:** [April 15, 2006, 2:21am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/10 "2006-04-15T02:21:08Z")

</div>

You can highlight within Devonthink. I’m curious if Christian can provide some help with scripting the highlight info in DTP. I could not find any information in the Devonthink Applescript dictionary about highlight colors. If it were possible to query the highlight color with Applescript, then it would be pretty easy to use Devonthink exactly how you would like without even using Tex-Edit.

---

<div class="post-metadata">

**Author:** ![MeitnikScholar](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@MeitnikScholar](https://discourse.devontechnologies.com/u/MeitnikScholar)\
**Post date:** [April 15, 2006, 2:38am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/11 "2006-04-15T02:38:23Z")

</div>

> [@Knight of Nee](#):
>
> > [@MeitnikScholar](#):
> >
> > > [@Knight of Nee](#):
> > >
> > > > [@MeitnikScholar](#):
> > > >
> > > > [size=18]  
> > > > I’m a little confused. What is the directory structure of the folder you are importing from? How many subfolders do you have? Are they always titled the same? I assumed that you had a folder filed with text files that you wanted imported into Devonthink. If there are other folders within, then this script will definately NOT work correctly.
> > > > 
> > > > As for converting txt files to rtf, there should be no reason to do that, unless you absolutley do not want the ability to format the text. I would just leave them as an rtf document.

I worked around the folder directory walk some. The text files are not in rtf; but to use the hiliter on them after importing they need to be converted into rtf. Btw, how do i append text to a rtf doc in devon. I have this code for now:

```auto
tell application "DEVONthink Pro"
	set wd_title to the name of think window 1 as string
	set wd_title to characters 1 thru -2 of wd_title as string
	set wd_title to wd_title & ", Quotes" & """
	set this_text to the selected text of think window 1 as string
	set nudata to return & (tab & tab & """ & this_text & """) & return & "===============" & return
	--set the clipboard to (wd_title & return & nudata)
	copy nudata to text end of think window wd_title -- this fails
end tell

```

thanks so much for the help. 🙂

andrew

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [April 19, 2006, 11:17am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/12 "2006-04-19T11:17:45Z")

</div>

> [@Knight of Nee](#):
>
> You can highlight within Devonthink. I’m curious if Christian can provide some help with scripting the highlight info in DTP. I could not find any information in the Devonthink Applescript dictionary about highlight colors. If it were possible to query the highlight color with Applescript, then it would be pretty easy to use Devonthink exactly how you would like without even using Tex-Edit.

See [http://www.devon-technologies.com/phpBB2/viewtopic.php?p=13336#13336](http://www.devon-technologies.com/phpBB2/viewtopic.php?p=13336#13336)

---

<div class="post-metadata">

**Author:** ![system](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/4/4e6ff70c96be2eb307a274d890bba8d71ba671b3.png) [@system](https://discourse.devontechnologies.com/u/system)\
**Post date:** [January 21, 2022, 10:57am UTC](https://discourse.devontechnologies.com/t/disabled-scholar-needs-help-with-some-scripting-tasks/2590/13 "2022-01-21T10:57:01Z")

</div>

Closed on January 21, 2022, 10:57am UTC


