Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Appending new text to a .txt file? (Read 5158 times)
troubledworkflow
Full Member
*
Offline



Posts: 19

Appending new text to a .txt file?
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)
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Appending new text to a .txt file?
Reply #1 - Jun 12th, 2014, 4:08pm
 
You'll need a way to tell whether the links have already been appended.
Back to top
 
 
WWW   IP Logged
troubledworkflow
Full Member
*
Offline



Posts: 19

Re: Appending new text to a .txt file?
Reply #2 - 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?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Appending new text to a .txt file?
Reply #3 - Jun 13th, 2014, 10:54am
 
For loops see here, and .each().
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
troubledworkflow
Full Member
*
Offline



Posts: 19

Re: Appending new text to a .txt file?
Reply #4 - Jun 13th, 2014, 6:13pm
 
Thanks. It seems to be working:

$LinkTypeSimilar.each(X) {
                        if (!$TheFileText.icontains(X))
                           {runCommand(echo + " '" + X + "' >> " + $TheFile);}
                        };
Back to top
 
 
  IP Logged
troubledworkflow
Full Member
*
Offline



Posts: 19

Re: Appending new text to a .txt file?
Reply #5 - 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
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Appending new text to a .txt file?
Reply #6 - 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
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
troubledworkflow
Full Member
*
Offline



Posts: 19

Re: Appending new text to a .txt file?
Reply #7 - Jun 14th, 2014, 1:08pm
 
Ah, great. Thanks!
Back to top
 
 
  IP Logged
troubledworkflow
Full Member
*
Offline



Posts: 19

Re: Appending new text to a .txt file?
Reply #8 - 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?
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print