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:
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
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”
Here is something I scripted using Tex-edit with help from a friend to show a flavor what I need:
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.
[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.
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
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.
Ok, now it imports the file to each group. Do you want the “Comments” and “Quotes” files to be empty from the start?
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=“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:
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.
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.
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:
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