Hi,
I was wondering if someone could suggest a script to split a note at a particular character, like say ++ , then remove the ++ and put the first sentence of the section as the title, and make this recursive for any number of occurrences in a selected note, or even better for a selection of notes. This way it would be possible to go through a note and add these split characters to sections you want to split for an entire note (or set of notes), which is especially handy if you have longer notes to split. I’m a former user of Infoselect and this was a feature I loved in that program. Thanx.
Just had a look at this script and it works ok. However, it converts my rtf notes to text and also appears to add the word “text” to the subject line in the sidebar. Any idea how I would doctor this script to leave things as rtf and not put “text” in the title of the slit note? This is an incredibly powerful script if you have a lot of notes to separate. I personally replaced the suggested delimiter with “++”.
-- Split InfoSelect topic
-- Created by Eric Böhnisch-Volkmann
-- Copyright (c) 2005. All rights reserved.
using terms from application "DEVONthink Pro"
tell application "DEVONthink Pro"
activate
try
set this_selection to the selection
if this_selection is {} then error "Please select some contents."
my split(this_selection)
on error error_message number error_number
if the error_number is not -128 then
display dialog error_message buttons {"OK"} default button 1
end if
end try
end tell
on split(these_childs)
local this_child, oldDelimiter
tell application "DEVONthink Pro"
set oldDelimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to "--" & (ASCII character 10)
repeat with this_child in these_childs
set this_text to plain text of this_child
set AppleScript's text item delimiters to "--" & (ASCII character 10)
if (exists parent 1 of this_child) then
set this_group to parent 1 of this_child
else
set this_group to missing value
end if
repeat with this_element in every text item of this_text
set theName to paragraph 1 of this_element
create record with {name:theName, type:txt, plain text:this_element} in this_group
end repeat
end repeat
end tell
end split
end using terms from
The late, lamented Hog Bay Notebook had a feature whereby you could drag the contents of a note whose paragraphs were denoted by a - (eg an outline) into the list pane of a window (as in DT’s “Split” view) and instantly divide it into several notes, each headed by the first line of the corresponding paragraph.
Thus, if the note contained:
Apples
Bananas
Carrots
you would get three notes: Apples, Bananas, and Carrots.
Just tried this but the script doesn’t append “text” to the title over here. Rich text scripting of Mac OS X is still limited to visible/displayed text, therefore this would require a completely different and more complex script.
Unless you’re willing to do the actual parsing of the RTF yourself, I’d suggest looking at applescripting TextEdit to do what you want. I’d make my record separator have some strange attribute that doesn’t appear in your document: a bullet (opt-8) that’s bold and purple, for example.
You could then get the attribute runs of the text which would be broken by your bullet:
{"•", " Entry #1", "•", " Entry #2"}
and you could create separate documents from there.
Try:
tell application "TextEdit"
attribute runs of text of document 1
end tell
This is precisely what the script in question here does, only it first converts to text, which I don’t particularly like. Try out the script. You just need to edit the attribute, which could be a single dash, although I don’t recommend it. Pick something not in use in your text documents, like ** or something like that.
Hi, I see it is working properly now. I guess I can just convert back to rtf. Only problem is that all formatting gets lost. I guess it’s a quick and dirty solution for now unless someone comes up with something more elegant. Cheers
tell application "DEVONthink Pro"
attribute runs of rich text of content 1 of database 1
end tell
The thing you have to grapple with (which shouldn’t be a big problem) is that every format change sparks a new item in the list of attribute runs. So you might have 1 attribute run after a split marker, or you might have 5, depending on the formatting of your RTF document.
But anyway, just iterate through the list of attribute runs, and accumulate items until you hit the split marker. Then create a new RTF document from the accumulation and repeat until done.
I see where the word ‘text’ comes in in the title. It occurs when you convert the text files back to rtf. It adds ‘text’ to the end of the new item names in the sidebar.