Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Appending new text to a .txt file?
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1402603408

Message started by troubledworkflow on Jun 12th, 2014, 4:03pm

Title: Appending new text to a .txt file?
Post by troubledworkflow on Jun 12th, 2014, 4:03pm

Hi,
I want to continually append text to a .txt file connected to a note via $TheFile depending on what links the note has. I have managed to do this with the small script below. This works, but it repeats the append of every link every time it is run. Ideally, I would like to only append links that have not been previously appended. Is this possible?

runCommand(echo + " '" + links.inbound.similar.$Name + "' >> " + $TheFile)

Title: Re: Appending new text to a .txt file?
Post by Mark Bernstein on Jun 12th, 2014, 4:08pm

You'll need a way to tell whether the links have already been appended.

Title: Re: Appending new text to a .txt file?
Post by troubledworkflow on Jun 12th, 2014, 4:52pm

Is it possible to loop through the values of a "set" attribute? If so, I could first set the links as separate values of a set attribute and combine this with an if-statement, searching for each value in the text of $TheFile?

Title: Re: Appending new text to a .txt file?
Post by Mark Anderson on Jun 13th, 2014, 10:54am

For loops see here, and .each().

Title: Re: Appending new text to a .txt file?
Post by troubledworkflow on Jun 13th, 2014, 6:13pm

Thanks. It seems to be working:

$LinkTypeSimilar.each(X) {
                        if (!$TheFileText.icontains(X))
                           {runCommand(echo + " '" + X + "' >> " + $TheFile);}
                        };

Title: Re: Appending new text to a .txt file?
Post by troubledworkflow on Jun 13th, 2014, 6:56pm

It would be nice to add the creation date of the note linked from. Code below just grabs the name. Is it possible to add the creation date as well (without creating a new value for the date)?

$LinkTypeSimilar=links.inbound.similar.$Name

Title: Re: Appending new text to a .txt file?
Post by Mark Anderson on Jun 14th, 2014, 10:44am

I don't think the last links() parameter (default: $Name) can be an expression such as $Name+" "+$Created. So use an extra attribute $MyString.

Get the target note's rule 9or an agent to run this code:

$MyString = $Name+" "+$Created.format("l")  --> "A note 28/01/2011"

Now use this for your links() call:

$LinkTypeSimilar=links.inbound.similar.$MyString

Title: Re: Appending new text to a .txt file?
Post by troubledworkflow on Jun 14th, 2014, 1:08pm

Ah, great. Thanks!

Title: Re: Appending new text to a .txt file?
Post by troubledworkflow on Jul 8th, 2014, 5:51pm

$LinkTypeSimilar.each(X) {
                       if (!$TheFileText.icontains(X))
                          {runCommand(echo + " '" + X + "' >> " + $TheFile);}
                       };

So, the above code is working correctly for most links. A problem I'm having is when a $LinkTypeSimilar contains a parenthesis or bracket. It then doesn't recognize that it has been previously added to $TheFileText. Escaping the characters with backslash \ (\( and \]) does not help. It is strange. Is there a way to make it work?

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.