Tinderbox Forum

Tinderbox Meetup- Meetup 23OCT22 Working with Action Code, a Step-by-Step Walkthrough

Tinderbox Meetup- Meetup 23OCT22 Working with Action Code, a Step-by-Step Walkthrough

Level Intermediate
Published Date 10/23/22
Revision 1
Tags 5CKMEl, 5Cs of Knowledge Management and Exchange, Action Code, Development, Logging, Parse, Split, Stamp, Text Transformation
Video Length 01:31:18
Video URL Tinderbox Meetup 23OCT22 Using Split to Parse Data - YouTube
Example File TBX L - Meetup 23OCT22 Using Split to Parse Data.tbx (372.2 KB)
TBX Version 9.3
Instructor Michael Becker

In this meetup, we cover a range of topics: we discuss numbering outlines and do a deep dive into parsing a note name with the split dot operator. We explore the use of attributes, variables, stamps, factions, and logging. We also discuss various edge cases to consider, e.g., how to care for semicolons when working with lists.

The lesson we went through today is in response to a Tinderbox Forum post by @jprint714: How to name $Title and move $Text for notes containing bracketed titles? . This post is the basis for a wonderful tutorial that gets at the root of action code, logging, text transformation, note name path management and more.


Parse the text in an attribute and place the different parts in different attributes.

Learning Outcome

  1. Know how to use .split operator
  2. Appreciate the retention of your source data until you’re ready to destroy it
  3. Missed typed operators can lead to data being inexplicably destroyed (see LO2)
  4. Logging is your friend, helps you see what’s going on.
  5. Commenting code is your friends, it helps your future-self
  6. There is more than one way to do something
  7. Understand RegEx operational characters and how to escape them
  8. Tinderbox’s syntax for finding keys in a list or dictionary, e.g. [0], [1].
  9. User of designators, e.g. a note name, path, to enhance action code.
  10. The use of variables
  11. Appreciate the value of cleaning up after yourself
  12. Bonus: writing in markdown gives a ton of flexibility
  13. Bonus: some visual affordance really help, e.g., views, separators, and badges
  14. Bonus: replacing tricky characters, e.g., “;”, in operations with a different delimiter to complete a process and then later refers back to the original.
  15. Bonus: Triggering functions.


Parse this text “{1492: Columbus Sails} Columbus departs from Palos, Spain” that is in the $Name of a note.

  1. Place the text between the{} in the $Name
  2. Place the remaining text in $Text
  3. Do it in a way that leaves no lingering data

The Solution

See the stamps. I’ve produced several for the exercise:

  1. Reset
  2. Parse Name Original 0, the stamp that does not work
  3. Parse Name Original 1, simple stamp
  4. Parse Name Original 2 Modified, handles “;” in text.
  5. Parse =Name Refined Eg 1 Use Attribute Placeholder, uses attributes as a placeholder
  6. Parse Name Refined Eg 2 Use Variable uses variables instead of attributes.
  7. Tigger Parse Note, triggers a function to parse the note

See the functions, I’ve created two functions.

  1. fParseNote, parses the note on a boolean trigger
  2. fReset, resets the note on a boolean trigger

Please support aTbRef and Mark Anderson

Please donate to Market Anderson. Mark has set up a PayPal channel (Donate) to receive donations for his work on aTbRef and the community. I’ve set up a monthly contribution for him. As an aside, I regularly share parts of my Patreon proceeds with him—typically via an Amazon UK gift card—whenever he helps me/us with a big part of what we go over. I thank you for your support of Mark.

1 Like

Chat log - thanks to @archurhh

1 Like

@eastgate, follow-up on yesterdya’s call, how could I use the above appter to split a title note at the first and only the first comma? Let’s say I had “The Dog Is Red, red dogs are really big, fun, and I want one.”

I want the name to be “The Dog is Red” and the Text to contain the rest. using yesterday’s method the text breaks at big. I can’t use .captureRest because then I lose “The Dog is Red”. I can’ seem to figure out how to have the RegEx stop at the first comma, stick the proceeding in the $Name and the rest in the text.

Use case: I’m converting PowerPoint pullets to notes.

I’d reach first for the stream parsing operators, which make short work of the problem. (Capturing PowerPoint pullets is quite a challenge, because they run around the farmyard and squawk, even if they don’t have PowerPoint.)

[the string].captureTo(",","Name").captureRest("Text")

For regex, this is trickier because the pattern (.*),(.*) will first match the largest run of characters that precede a comma. What you want is a minimal match: (.*?),(.*)

I think, on balance, the streaming operators are easier and clearer.

1 Like

Ah!!! Very cool. This will solve another challenge I’m working on. Much appreciated.

So, it looks like .captureRest goes to the end of the line and stops. What would you do if you wanted to carry through to the end of the document?

Keep iterating. Stream processing works on all the input string (e.g. if $Text then all of $Text) a line/paragraph at a time. IOW, most Stream processing operators test part/all of the line to find the bit to capture and the latter is broadly to the end of the line. So, does the line start ‘To:’? Yes, move the stream cursor forward and catch the rest of the line. Now find the next line occurring that starts ‘From:’, capture that value.

Note the example I’m giving of something like an email where the definable target markers, e.g. ‘To:’, occur once in the source string and also likely in an expected order. In your latter case and ones discussed in some other current threads, the anchors may occur zero or more times and not in consistent order.

For the latter stream processing can be used, but by iterating each line/paragraph using Stream.eachLine(), e.g. $Text.eachLine(aLine{.... Now each line can still be processed as a Stream. But, as your order of occurrence and frequency of occurrence of target makers is ad hoc you may need to use a number of self-contained if() tests or using [Stream.try{action}.thenTry{action}](https://www.acrobatfaq.com/atbref9/index/ActionsRules/Operators/FullOperatorList/StreamtryactionthenTryac.html).etc..


Meet-up video: Tinderbox Meetup 23 Oct 2022 on Vimeo