It is currently April 17th, 2021, 3:03 am

TailFile

Skins that control functions in Windows or Rainmeter
User avatar
jsmorley
Developer
Posts: 21635
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

TailFile

Post by jsmorley »

This skin demonstrates how you can "tail" some number of lines from a text file, like a log file or to-do list or any other file you would like to see some number of the "most recent" items added to the bottom of the file, in reverse order.

This uses a very simple Lua script to read the file. The Lua then sets some number of String measures in the skin that are in a sense acting as "child" measures to the Lua Script measure. The meters then use the values of those String measures to display the lines.

You can simply change the file you want to read in [Variables] and use this as is, or feel free to tear it apart to use the underlying functionality in your skin.

I think it is pretty easy to follow what it is doing, but feel free to ask any questions.
TailFile_2.0.rmskin
1.jpg
Note that you easily could add IfMatch conditions to the String measures, which would for instance allow you to monitor for "error" in a log file, and set a font color different or any other action you like. You could also use RegExpSubstitute to replace text in the line, so for instance you could remove unwanted tabs or spaces, remove the first "xx" characters of the line, or any other change you might want to make with a regular expression search-and-replace.


Important: If you are going to have Unicode characters in the text file you are reading, that file MUST be encoded in UTF-8 with or without BOM. That is the only encoding supported by Lua when reading external Unicode files.
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 21635
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: TailFile

Post by jsmorley »

Updated the Lua code to use a vastly more efficient method for reading the last N lines of a large file. The Lua code is based on work by Brian in This post.