Tinderbox Forum

How to auto-populate attribute based on note text

Hi, I’m using the AutoFetch function to have my $Text updated from a Devonthink URL. In that Devonthink RTF, I have a heading called ‘Quick Summary’. I’d like to take any text that comes after that heading and before the next one ('Structure & Notes) and automatically place it in my user-defined attribute ‘Quick Summary’.

Is there a way to do this?

Thanks so much in advance for your help!

Sure. In an agent, for example, you might extract the text using a regular expression

Query: Text.contains("Quick Summary (.*)")

which means "find Quick Summary and then remember everything to the end of the line.

The action uses $1, which means “the first matched sub-expression in parentheses”

Action: $MyString=$1

Of course, this will need to be adjusted to the details of your data!

1 Like

Further to the above… Bear in mid that if you’re storing something in an attribute ($QuickSummary), that the Key Attribute table is the most likely way you’ll view it. So, make sure your summaries are short or you won’t be able to read them easily—a lesson learnt from (trying to) use a similar technique. The app isn’t the limitation here but rather out lazy untested assumptions. Pro tip: experiment.

Thanks so much for the help! This is working great - mostly :slight_smile: The only issue is that it’s picking up everything after the Quick Summary line too.

I have the agent’s query as: Text.contains(“Quick Summary:(.*)”)

And (in this example) I’ve set the agent’s action as: $Subtitle=$1

And this is what it returns:

Am I doing something wrong?

Wrong? No. It is just that your .contains() regex pattern is too permissive. Likely an assumption that the summary was at the end of text. Plus, it can be confusing knowing when/in what contexts patterns work across line breaks (i.e. paragraph boundaries).

So, to test a better solutionI started a three paragraph test piece with the summary in the middle:


Having got a successful result, I added two edge cases where the summary is the beginning or the end of the $Text.


Again, a correct result so I can report the agent’s action is $Subtitle=$1 as before but the revised queryis :

$Text.contains("Quick Summary: ([^\n]+)")

The regex parsed as pseudocode: The string "Quick Summary: "†, open a back-reference, match one or more non-line break characters‡, close back-reference

† This is case-sensitive so adjust for your summary label. Don’t forget the space(s) after the colon and before the actual summary text.

‡ i.e. match to the end of that paragraph (or end of the $Text if the last paragraph). This allows for your summary to be several short sentences if needs be. Note that detecting a sentence end is harder as you need to allow for full stop, question mark, exclamation mark, straight/curly single/double quotes (if those come after the punctuation mark - a BrE/AmE difference).

As you are using a subtitle, you probably don’t want to see the body $Text of the note. Shown by default, this can be suppressed. See $MapBodyTextSize.

Just to round out the above, here I have duplicated the original test note and set $MapBodyTextsize to a value of 1:

Although the note’s $Text is the same, you can see that only the title ($Name) and subtitle ($Subtitle) are shown on the map icon.

Also be aware that body text ($Text) can be displayed in the default note shape ($Shape) of ‘rectangle’. All other shapes only support title ($Name) and subtitle ($Subtitle), as well as a caption ($Caption - which is drawn outside the map icon).

Wow! Thanks you so much! I’ve been able to do exactly what I wanted (and more!) with that info. I really appreciate the time you’ve both taken to explain how each of the elements work – it’s so helpful when you’re learning :smiley: :raised_hands:

On that note, do you have any recommendations of where someone like me (with very little coding experience) should look to learn the syntax and method of writing Tinderbox queries/actions?

Yay! Always glad to hear folks moving ahead in their Tinderbox use. As to your question, if you’ve not yet found it, do take a look at aTbRef—disclaimer: I’m its author. aTbRef is a reference, not a how-to but this listing is a useful jumping-off point to look at the kinds of things you can automate.

If it helps any, I’ve been using computers for >30 years never never had a day’s instruction in ‘coding’, yet I can find my way around the app. The secret is not to concentrate on the overall outcome but to break the task into little parts: make a list of things, extract a relevant part from each item into a new list, etc., etc. Daunting at outset, but not so scary once you get going and your fellow forum users are here to help. :slight_smile:

Thanks, Mark! I’m looking forward to exploring even more now :smiley: