Tinderbox Forum

Identifying paragraph text

Am setting up a new project that will integrate notes from Tot. The expected work flow:

  1. Write a note in Tot that has as first line (ie first paragraph) a descriptive title, a topic in the second paragraph (admin, bio, math) and the note itself.

  2. The note is imported and some user defined key attributes are populated. This is what I am asking help for.

  3. In TBx, I will open an imported note and apply a stamp that copies the imported note to the end of an existing ‘collection’ note in the three areas (admin, bio, math). Then I integrate the idea by some means.

The second step should be simple, but the code in the image is not working. What’s wrong?

https://www.dropbox.com/s/e5cutpqp3i6o3sz/Screenshot%202020-06-11%2012.16.55.png?dl=0

OK, this is the code I see:

$DisplayExpression = $Text.paragraph(0);
;
if($Modified!=$lastmodified){
	$Badge=Tot4
}else{
	$Badge=Tot4a
};
if($Text.paragraph(1)=admin){
	$TargetFolder=\Target Container\Note
};

Doing some tidying:

$MyString = $Text.paragraph(0);
$DisplayExpression=$MyString;
if($Modified!=$lastmodified){
	$Badge="Tot4";
}else{
	$Badge="Tot4a";
};
if($Text.paragraph(1)="admin"){
	$TargetFolder="/Target Container/Note";
};

Several points (reading top-to-bottom):

  • Normally I’d avoid a calculated display expression so we’ll store the literal value in $MyString. As there are only 5 Tot notes and this isn\t a complex expression, this might be over-optimisation—feel free to skip this.
  • Is the letter case of $lastmodified correct? It looks to be a valid attribute name string, though typical convention (not a requirement) is to use CamelCase for user attribute names. If using other conventions for your user attributes, name case is something definitely to check if code goes awry, not least as you also have a user attribute that does use CamelCase (thus the opening question).
  • I’ve quoted literal strings in the two $Badge allocations and the last conditional text & code. This stops Tinderbox contextually having to guess is this a literal string, an attribute name, a title or path, etc.
  • Setting $TargetFolder. I think this is the likely problem as you’ve used a back slash (escape) where you intended a forward slash (path folder delimiter). Although we are storing a path, at this stage we are storing a string, so I’ve added quotes so as to make a literal string.

† Tinderbox uses POSIX-type path conventions as per current macOS

Anyway, give that a try. :slight_smile:

Thanks Mark. I had tried all combinations of slashes and quotes, including by accident the correct ones. As it happens, the code works fine on a natively created note, but not imported Tot text. The maddening thing is that the code DOES correctly find the paragraph 0 text. Will try another scheme.

FWIW, I’ve updated the article on watching Totto try and make it a bit clearer (e.g. that actively watched notes are read-only)

OK, which specific bit is failing, so we can Narrow this down?

Is ‘admin’ the whole of para 2 of the note. Otherwise .startsWith() or .contains() might be needed.

I did a quick check, watching my Tot. I added a string-type $TargetFolder and this stamp:

if($Text.paragraph(1)="admin"){
	$TargetFolder="/Target Container/Note";
	$Badge="ok";
};

The $Badge test is to check it will set on a read-only note. I then set two tot notes’ second paragraph, one a ‘admin’, one as ‘admin’. I applied the stamp, the first met the ‘if’ test and populated $TargetFolder and $Badge—as I would expect—the second did not change due to the full stop in paragraph 2.

I hope that help with the de-bugging. Here’s a grab of my result

Note the .paragraphs() operator ignores line-spaced paragraphs. IOW, \n\n is tread as '\n` when breaking out the paragraphs.

$DisplayExpression = $MyString

will evaluate $MyString and display the result. So, if your note’s first paragraph is 2 + 2 is 4!, Tinderbox will display 4 is 4.

You probably want:

$DisplayExpression= '"' + $MyString + '"'

1 Like