I have been wanting to do this for sometimes and finally got to it. I use DTTG to take meeting notes. When a task is necessary I use a separate line with the keyword “ACTION:” and text corresponding to the necessary action to be taken.
Once the notes are sync back to the Mac (once per day), I collect all of them and make entry in my task manager, Things.
Not sure it is the most efficient (not a scripting expert!) but it seems to work and I even attached it to the CMD-F15 key for quick use
-- Script to automatically scan a text file within DevonThink Pro or DevonThink Pro Office, extract task items and send them to Things
-- Written by Luc Beaulieu, Version 1.0, March 7, 2015
-- Re-use portions of a script "Add as To Do to Things" written by Eric Böhnisch-Volkmann, Version 1.0.1, Jan 28, 2010
-- Set properties
property pTags : "DEVONthink"
try
-- Get the selection
tell application id "com.devon-technologies.thinkpro2" to set thisSelection to the selection
-- Error handling
if thisSelection is {} then error localized string "Please select a document, then try again."
if (length of thisSelection) > 1 then error localized string "Please select only one document, then try again."
-- Get and format the data we need
set pLocalizedTags to localized string of pTags
tell application id "com.devon-technologies.thinkpro2"
set theSource to content record
set theText to plain text of theSource
set theLines to paragraphs of theText
set thisItem to first item of thisSelection
set theSummary to (name of thisItem) as string
set theURL to ("[url=x-devonthink-item://" & uuid of thisItem & "]" & name of thisItem & "[/url]") as string
end tell
-- Iterating through each line, one by one, for the string delimeter "ACTION:"
-- and create a new task in Things global Inbox if appropriate
set textDelim to "ACTION:"
set nTask to 0
repeat with eachLine in theLines
set nextLine to eachLine
set finalTask to ""
if nextLine contains textDelim then
set AppleScript's text item delimiters to textDelim
set theTask to item 2 of every text item of nextLine
set AppleScript's text item delimiters to ""
set finalTask to finalTask & theTask
-- set finalTask to finalTask & theTask & return
end if
if finalTask is not equal to "" then
set nTask to nTask + 1
tell application "Things"
-- create task entry in Inbox with a link back to the meeting notes
make new to do with properties {name:finalTask, notes:theURL, tag names:pLocalizedTags}
end tell
end if
end repeat
display dialog (nTask as string) & " were created!"
on error errMsg
display alert (localized string "Error extracting task") message errMsg
end try
This is a clever idea, and it’s great that you posted it. It will prove useful for other readers who use Things, and could be adapted (I imagine, for OF and other task managers).
There are a few things I’m not sure I follow. You have two “tells” to DEVONthink that use different syntax to grab the same record. In the first “tell” you pick up the selection and terminate the script if there is more than one item selected. This is of course the first item of the selection. The first item of a selection, in the case where the that item is a document record, is the same as the content record. Your second “tell” picks up the “content record”. The DEVONthink portion of the script will operate just as well if you just choose the content record and don’t bother with the selection. This isn’t criticism – just curiosity about your structure.
There is a property of DEVONthink records, Reference URL, which can be used in place of building up the reference url manually.
For avoiding obsolescence, it’s good practice to tell application ID “DNtp”, using an application’s four-letter creator code rather than the bundle ID. The ID for Things is Thgs
Well, the structure here is similar to that written by Eric for the “Add To Do to Things script”. The first “tell” makes sure that there is only one and only one file selected. I suppose that the script could be modified to handle an arbitrary number of files.
Second, I had a lot of trouble accessing the content of the file from “selection” (or “thisSelection”). The script I used when reading directly a text file from the Desktop was different probably because within DT, a text file and not simply a text file anymore but an object (exempt if I use the full POSIX path/name to open it). Also I was never able to use “thisItem” the same way as “theSource” i.e. simply parsing the string as I did, thus my use of “content record” to get access. Maybe I missed something… but again I am certainly not an AppleScript expert
In both case here, I again used the existing syntax from Eric’s scripts that comes with DT as examples. This also probably means that I can simplify the script and make it more elegant!
Coders have their styles. I’m merely suggesting a terser approach that works for me. Your code (Eric’s code) is fine. This snippet explains other options:
tell application id "DNtp"
set theRecord to the first item of (selection as list)
set theCRecord to the content record
if theCRecord is missing value then display dialog "CRecord is a Group"
if the type of theRecord is group then display dialog "Record is a Group"
end tell
The first line shows how to grab the first record in the selection.
The second line is the same result IF the content record is not a group
So, the third line throws a warning if the content record is a group (because AppleScript will return a missing value error if you select a group)
And, the fourth line throws a warning if the first item in the selection is a group
The last two, because your script will only operate correctly on non-group text-contain records.
FWIW - thanks for posting this, and the comments/discussion about the script. Really helps scripting neophytes like me, get their heads around what is what.
To the OP - interesting use of DTTG, plenty of food for thought there.