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
Two quick questions (Read 12066 times)
gilbertb
Full Member
*
Offline



Posts: 6

Two quick questions
Mar 03rd, 2008, 4:27pm
 
Can i set up a note in tinderbox to reference a text file for the note text ?
I'd like to have a set of text files that I'm editing with textmate but have that text reflected in a note in tinderbox
Kind of the way tinderbox fetches webpages
Back to top
 
 
  IP Logged
Ioa Petra-ka
Full Member
*
Offline



Posts: 103
Portland, Oregon, USA
Re: Two quick questions
Reply #1 - Mar 3rd, 2008, 5:46pm
 
Yes, in fact right in the same spot as the set-up for fetching from the net, you can set up what you are looking for. The attribute AutoFetchCommand will execute when AutoFetch is enabled. Try something like this in AutoFetchCommand:

Code:
Text=`cat ~/Documents/some_text_file.txt 



Then, with AutoFetch set to true, open the note. It should have the contents of the file loaded already. Everything to the right of that ` symbol is sent to the UNIX shell. So you can run pretty much anything in there that prints to STDOUT and get the results imported automatically into Tinderbox.

Note, if you meant "text file" in the non-purist sense, and what you are trying to import is actually RTF or something, you'll want to use a different command. Something like:

Code:
Text=`textutil -stdout -convert txt ~/Documents/some_rtf_file.rtf 

Back to top
 
« Last Edit: Mar 3rd, 2008, 5:49pm by Ioa Petra-ka »  

Av
  IP Logged
gilbertb
Full Member
*
Offline



Posts: 6

Re: Two quick questions
Reply #2 - Mar 3rd, 2008, 7:11pm
 
Fantasic this works! Now if I could take it one step furthur .  If I could set up a rule where the text of the note would automatically be the text of a file that I link to in the file attribute ? I noticed that the file attribute stores it's file path using colons.
Back to top
 
 
  IP Logged
Ioa Petra-ka
Full Member
*
Offline



Posts: 103
Portland, Oregon, USA
Re: Two quick questions
Reply #3 - Mar 3rd, 2008, 9:30pm
 
Bi-directional is going to be more tricky. The potential for the Rule and AutoFetch stampeding all over each other would exist, and you might risk losing data one way or the other. In this matter, personally, I would be less inclined toward automation. It would certainly be possible to write out files using a Rule, the question is whether that would be prudent. For one thing, file operations are going to be slower than other Rule actions. If you have a bunch of them constantly writing to the hard drive it would needlessly wear out your hardware and slow down your system. Then there is accidental data loss to consider. Example: You spend a day writing in TextMate, then a few days later open your Tinderbox document. AutoFetch doesn't run until the notes are opened (I think... though there might be a delay), but the Rules are going to run instantly and constantly---they will export the days-old content right into your files without even asking if that is what you want to do.

Alternatively: Tinderbox is a very capable exporter, and while its default system attributes are all set up for HTML export, it is fairly simple to circumvent that with a few attribute modifications, file extension adjustments, and so forth. With a little customisation, the "HTML" exporter can be informed to export nearly any file format. The advantage of using that over the text exporter is that it can retain file structures. You could mirror the directory you wish to keep up to date, in Tinderbox, and when you export the files and folders will all end up where you would expect them to.

Another alternative would be to roll your own exporter. This could be accomplished with a few attributes and a couple agents. I would store the path and name of the file in a string attribute instead of using the File attribute because of the path addressing differences. Tinderbox uses the legacy Mac method of displaying paths with colons, as you noted. Then a boolean attribute "ExportNow" or something, which triggers an agent with an AgentAction containing the export action, and finally un-sets ExportNow, making it a one shot deal. In other words, exporting becomes an intentional, per-document decision. Of course, you could set it up to export an entire range of documents once, too. It would all depend on how you set up the attributes and agents.

I would definitely try playing with the HTML exporter first and see if that is going to work for what you need. Any other route is going to be potentially complicated . HTML export comes in two flavours: Single-note export (Cmd-Opt-H), and full document export (Cmd-Shift-H). The latter respects an exclusion attribute, so you can narrow down what "full document" means.

One thing is clear, if you are going to want bi-directional, AutoFetch probably isn't what you want. It would be too easy to accidentally lose work. All it would take is typing in a note for a while, forgetting to export, and then re-opening the note later.
Back to top
 
 

Av
  IP Logged
gilbertb
Full Member
*
Offline



Posts: 6

Re: Two quick questions
Reply #4 - Mar 4th, 2008, 3:11am
 
Wow I really appreciate you help with my questions your very informative and obviously know tinderbox well.
I guess what I'm looking for wasn't necessarily Bi directional. I really just wanted to have the attach a text file to a note and have the file path read from the file and then the text in that file becomes the text of the tinderbox note in a sort of read only mode. I would only be able to edit the text externally almost as if the note is a window to the text file . For instance I have a file structure that I want to  baiscally mirror in tinderbox what I have on disk but I want the ability to add tinderbox attributes and what not to organize and alias the files. I would also have that same file sturcture in a  textmate project while it would be a pain to keep the two in sync it would still seem usful. The note's text would be a window to the textfiles content . I would then be able to use tinderbox to track and file the textfile inside Tinderbox but the only way I would edit the file is in textmate . If I decided that the attached file is incorrect or I am given an updated file from another person. I can attach that new file and the text of that file becomes the notes text .
I suppose this is in lieu of being able to open a notes text in textmate and return when finished. Tinderbox's interface is aging some of it is really annoying but I can't find a program to replace it  and really like the program. I'll have to look over the export and text template options as I've not done that . It would also be e interesting if I could figure out how to export a task list in taskpaper format ???? Maybe aproject for another time . thanks so much for your responses again very enlightening.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Two quick questions
Reply #5 - Mar 4th, 2008, 4:47am
 
Sourcing you AutoFetched note's content from a File path is possible. OK, first you need to set the note's URL attribute to be the path storeed in the File attribute.  But you can't just set an action URL=%File as the File path will look like this:
Macintosh HD:Users:mwra:Desktop:Path test.txt
and the URL needs to be in this form:
file:///Users/mwra/Desktop/Path%20test.txt
So you'll need to urlEncode() your File path and use a script a regular expression to swap out colons for slashes plus remove the path's volume name replacing it with the file:// protocol. Using my example above you'll go through stages (within the action & script) like the following, where 'xyz' is the short name form of the current user's account.

Read the File attribute
  Macintosh HD:Users:xyz:Desktop:Path test.txt (=value of $File)
  Macintosh%20HD:Users:xyz:Desktop:Path%20test.txt (=value of urlEncode($File)
  Macintosh%20HD/Users/xyz/Desktop/Path%20test.txt (after shell regexp replace colons->slashes)
  /Users/xyz/Desktop/Path%20test.txt (after shell remove volume name)
  file:///Users/xyz/Desktop/Path%20test.txt (after shell prefix with 'file://' protocol)
...then pass to URL attribute as value


[post edit: this is a conceptual answer - I've not successfully tested it to through to the OP's desired result]
Back to top
 
« Last Edit: Mar 4th, 2008, 9:38am by Mark Anderson »  

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



Posts: 103
Portland, Oregon, USA
Re: Two quick questions
Reply #6 - Mar 4th, 2008, 8:29am
 
To do all of that, the Rule you would want would look something like:

Code:
URL=`echo -n $File | sed -E 's/:/\\//g\;s/ /%20/g\;s/^[^\\/]+/File:\\/\\//' 



I wasn't able to get a file fetching off of my hard drive in this manner, though. I got a strange 404 error.
Back to top
 
 

Av
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Two quick questions
Reply #7 - Mar 4th, 2008, 9:36am
 
Amber, your CL gives me - with a text file on my desktop as $File - a truncated URL value of 'File://'. Regexp issue? I'm not CL/regexp savvy enough to fully understand the sed syntax!

Testing my above idea a bit further, again with a 'txt' file on my desktop, I find that if I explicitly set the correct file:///etc.... URL ViewInBrowser 'true' opens the file in TextEdit but when false the note doesn't show any text. I also tried these as AutoFetchCommands:
runCommand("cat '"+$File+"'");
runCommand("cat '~/Desktop/some_file.txt'");


Perhaps we're pushing TB a bit too far in this context? I know Mark B's away at a conference right now but he may have a more authoritative view on what syntax is reasonable to try when he gets back.
Back to top
 
 

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



Posts: 103
Portland, Oregon, USA
Re: Two quick questions
Reply #8 - Mar 4th, 2008, 12:57pm
 
I meant to mention that this script is not particularly robust, and only briefly tested shortly after waking up and writing it. Wink That said, I cannot reproduce the error. I have placed on my desktop a file: Untitled.txt, created a new Tb document, a note; dropped the file onto the sidebar for the note, and then inserted the above action as a Rule. If you inverted the last two steps---that might be the issue.

Another problem is---yes we are pushing Tb. Part of why that regex is such a mess is that I had to escape stuff to get past Tinderbox's internal parsing. I think the command is a little fragile. If I paste it into Rule verbatim, with nothing else, it works. That rule by itself would be needlessly expensive, adding some logic to only run sed when necessary would be best, but putting the URL command into a logic block does not work. It needs to have the part sent to the shell wrapped in quotes. I never got just [font="Courier"]file://[/font] as a result, though. Whenever it malfunctioned in my test---URL came up empty.

Oh, one other limitation is that files cannot be linked from other disks, obviously, as the prefix would then need to retain the volume name, and look like [font="Courier"]file:///Volumes/volumeName/path/to/file.txt[/font]. So a better version would be:

Code:
if (File!="") { URL|=`"echo -n $File | sed -E 's/:/\\//g\;s/ /\\\\ /g\;s/^/\\/Volumes\\//' | tr -d '[:cntrl:]'"  } else { URL=; } 



ViewInBrowser also works for me---but if all you want to do is open the file, the File drop-down in the sidebar will accomplish that, and AutoFetchCommand would be a better way keep the note up to date.

Since that does not need the URL stuff, like the [font="Courier"]file://[/font] prefix, the final recipe would look like this.

Create attribute FileUNIX(string)

Rule: [font="Courier"]if (File!="") { FileUNIX|="'" +runCommand("echo -n $File | sed -E 's/:/\\//g\;s/ /\\\\ /g\;s/^/\\/Volumes\\//' | tr -d '[:cntrl:]'") + "'" } else { FileUNIX=; }[/font]

AutoFetchCommand: [font="Courier"]Text=`cat $FileUNIX[/font]

AutoFetch: true

Okay, now drag a file to the drop-spot (or browse to it, whatever). Close the note, open it again---should have file contents in the Text area. Use the drop-down to edit the file in TextMate. I believe this is the work-flow you are looking for, Gilbert? The contents of the Tinderbox note will always be up to date with the disk; the file can be easily opened and edited in TextMate without knowledge of the file system; and the files can then be organised using Tb's extensive features.

This will work for files on external volumes, files with spaces, and it should work for files with Unicode characters---but I didn't test that.
Back to top
 
« Last Edit: Mar 4th, 2008, 1:03pm by Ioa Petra-ka »  

Av
  IP Logged
gilbertb
Full Member
*
Offline



Posts: 6

Re: Two quick questions
Reply #9 - Mar 4th, 2008, 1:09pm
 
Brilliant !!! It works like a charm . Only caveat is I have to clear the file close the note and let the text window clear to nothing then attach a new file and it reads that file as well . This is definitly a motivator to get better at my shell scripting . Thanks for your help.
Back to top
 
 
  IP Logged
Ioa Petra-ka
Full Member
*
Offline



Posts: 103
Portland, Oregon, USA
Re: Two quick questions
Reply #10 - Mar 4th, 2008, 1:23pm
 
Right, I forgot to mention that specifically. In the event that the file changes for the note in question---you will have to clear the file link, then create a new one. I was assuming you would be creating one note per file, though. If you want a note to be more dynamic at the cost of performance, adjust the Rule so that FileUNIX=... instead of FileUNIX|=. The latter form of assignment checks for left-hand truth before assignment. If $FileUNIX is false (empty), then it assigns the right-hand value; all of the scripting in this case. If $FileUNIX is true, nothing happens. Hence it is a more resource friendly way of going about it. If the file has already been set, there is no need to keep recalculating its path name. Changing it to a straight equals means it will be constantly updating the path name---including any changes made to File.

You will still have to close and open the note window for contents to update. That is a limitation in Tinderbox. KeyAttributes do not update dynamically, either.
Back to top
 
 

Av
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Two quick questions
Reply #11 - Mar 4th, 2008, 2:50pm
 
Great, thanks for sharing that. Works fine here too.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print