Ace McKool | 10 Dec 20:18

LSX Command > Add text to file

Hi Everyone,

I'm trying to track my time at work.  I was hoping to use LSXCommand (plus
any needed modules) to do something like:

?tracker "Some Client > I did this for them"

And it would simply write the string to a file and add a timestamp if
possible.

Anybody have any recommendations on how to get this started?  Thanks!
Jochen Ritzel | 11 Dec 15:32

Re: LSX Command > Add text to file

Some Lua:
[code, copy to some file and *luascriptfile it]
-- config this.
local clienttracker = {
     OUTFILE = 'blah.txt',
     -- if you want some formatting, you can set that here
     INFORMAT = '%s*([^>]*) > (.*)%s*', -- the input string is parsed with  
this pattern
     OUTFORMAT = '%s | %s',          -- and formatted with this pattern  
afterwards ... you could add tabs ( \t ) here ...
     TIMESTAMP = true,
     TIMEFORMAT = '%c', --see  
http://www.thinkage.ca/english/gcos/expl/c/lib/strfti.html
     ERROR = function(self, msg )     -- if an error occures, it is  
reported with this function
         --lslua.message_box("An Error occured: ".. msg, "Error!" )
         print( "An Error occured:", msg )
     end
}

-- admire this.
function clienttracker:_format( client, text )
     local s = self.OUTFORMAT:format( client, text)
     if self.TIMESTAMP then
         return ('%s: %s\n'):format( os.date( self.TIMEFORMAT), s )
     else
         return s
     end
end
function clienttracker:parse( s )
(Continue reading)

Ace McKool | 11 Dec 20:45

Re: LSX Command > Add text to file

Thanks for this!  This is my first time with Lua, so I have a few follow-up
questions:

1.  Do I need any of the Lua packages to run this?  e.g. textedit?
2.  How do I confirm the path to the blah.txt file?  I tried:

OUTFILE = 'c:\\blah.txt"

but that didn't seem to work.  Thank you very much for this though, looks
pretty cool.

On Dec 11, 2007 6:32 AM, Jochen Ritzel <THC_rulez@...> wrote:

> Some Lua:
> [code, copy to some file and *luascriptfile it]
> -- config this.
> local clienttracker = {
>     OUTFILE = 'blah.txt',
>     -- if you want some formatting, you can set that here
>     INFORMAT = '%s*([^>]*) > (.*)%s*', -- the input string is parsed with
> this pattern
>     OUTFORMAT = '%s | %s',          -- and formatted with this pattern
> afterwards ... you could add tabs ( \t ) here ...
>     TIMESTAMP = true,
>     TIMEFORMAT = '%c', --see
> http://www.thinkage.ca/english/gcos/expl/c/lib/strfti.html
>     ERROR = function(self, msg )     -- if an error occures, it is
> reported with this function
>         --lslua.message_box("An Error occured: ".. msg, "Error!" )
>         print( "An Error occured:", msg )
(Continue reading)

Jochen Ritzel | 11 Dec 21:11

Re: LSX Command > Add text to file

Try this:

1. Save that code to some file, ie $ThemeDir$tracker.lua
2. Edit that OUTFILE, you best use a absolute path like 'c:\\blah.txt' or  
'c:/blah.txt' (windows does not care). If you use a relative path ( just  
'blah.txt' ) it is relative to your LitestepDir.
2. Edit your theme.rc file
	- add `*NetLoadModule lslua-0.6.5 load lslua`
	- add `*Luafile "$ThemeDir$tracker.lua"`
3. Recycle
4. Run !Tracker client > text

That should do it.

Ah yeah, uncomment ( remove the -- ) before `lslua.message_box("An Error  
occured: ".. msg, "Error!" ) and you'll see a more or less helpfull error  
message if something goes wrong.

On Tue, 11 Dec 2007 20:45:00 +0100, Ace McKool <face7hill@...> wrote:

> Thanks for this!  This is my first time with Lua, so I have a few  
> follow-up
> questions:
>
> 1.  Do I need any of the Lua packages to run this?  e.g. textedit?
> 2.  How do I confirm the path to the blah.txt file?  I tried:
>
> OUTFILE = 'c:\\blah.txt"
>
> but that didn't seem to work.  Thank you very much for this though, looks
(Continue reading)


Gmane