Skip to main content
added 135 characters in body
Source Link
Luke
  • 1.2k
  • 1
  • 9
  • 18

There are some comments in the code, but briefly it will: read 5 lines from the end of the specified log file,file; create a window and add this as text on the window,window; make the window transparent, always on top, and "unclickable""unclickable"; and update the text every 1 seconds (might need to increase this, but i don't see a huge performance hit - even with a 20mb log file).

There are some comments in the code, but briefly it will: read 5 lines from the end of the specified log file, create a window and add this as text on the window, make the window transparent, always on top, and "unclickable".

There are some comments in the code, but briefly it will: read 5 lines from the end of the specified log file; create a window and add this as text on the window; make the window transparent, always on top, and "unclickable"; and update the text every 1 seconds (might need to increase this, but i don't see a huge performance hit - even with a 20mb log file).

Source Link
Luke
  • 1.2k
  • 1
  • 9
  • 18

I've managed to get this to work, but you might have to play with the transparency / font size / background colour to get it so it is easy to read.

You'll need to install AutoHotKey and run this script: https://www.dropbox.com/s/x510z8tsxunardl/OSDTest.ahk

There are some comments in the code, but briefly it will: read 5 lines from the end of the specified log file, create a window and add this as text on the window, make the window transparent, always on top, and "unclickable".

To exit the script, right click the AutoHotKey icon in your system tray and choose Exit.

If my links are broken, the AHK code follows:

#SingleInstance force
; Example: On-screen display (OSD) via transparent window:
FileName := "C:\xampplite\apache\logs\access.log"
NumLines = 5
CustomColor = FF8080 ; The transparent background color of the window, set this to something close to your text colour to avoid white highlighting

Gui +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x20  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s12  ; Set a large font size (12-point).
errorTail := FileTail(FileName , NumLines) ; get the text from the file, last 5 lines
Gui, Add, Text, vMyText cRed Y+0, %errorTail%  ; add it, colour is Red, R5 sets 5 rows

; choose one of these lines, first one show just the text, second one has a background for readability
WinSet, TransColor, %CustomColor% 200 ; Make all pixels of this color transparent and make the text itself translucent (250)
;Winset, Transparent, 150

SetTimer, UpdateOSD, 1000 ; 1 second timer set here
Gui, Show, x0 y600 NoActivate  ; Set the x and y position. NoActivate avoids deactivating the currently active window.
return

UpdateOSD: ; the repeated timer routine
errorTail := FileTail(FileName, NumLines) ;get 5 lines
GuiControl,, MyText, %errorTail%
return

; ======================================================================================================================
; Function:    Retrieve the last lines of a text file.
; AHK version:  1.1.07+
; Parameters:
;    FileName -  the name of the file, assumed to be in A_WorkingDir if an absolute path isn't specified
;    Lines  -  number of lines to read - default: 10 (like Unix)
;    NewLine  -  new line character(s)   - default: `r`n (Windows)
; Return values:
;    On success: The required lines, if present
;    On failure: ""
; Version:      1.0.00.00/2012-04-16/just me
; ======================================================================================================================
FileTail(FileName, Lines = 10, NewLine = "`r`n") {
   Static MaxLineLength := 256 ; seems to be reasonable to start with
   If !IsObject(File := FileOpen(FileName, "r"))
      Return ""
   Content := ""
   LinesLength := MaxLineLength * Lines * (InStr(File.Encoding, "UTF-16") ? 2 : 1)
   FileLength := File.Length
   BytesToRead := 0
   FoundLines := 0
   While (BytesToRead < FileLength) && !(FoundLines) {
      BytesToRead += LinesLength
      If (BytesToRead < FileLength)
         File.Pos := FileLength - BytesToRead
      Else
         File.Pos := 0
      Content := RTrim(File.Read(), "`r`n")
      If (FoundLines := InStr(Content, NewLine, 0, 0, Lines))
         Content := SubStr(Content, FoundLines + StrLen(NewLine))
   }
   File.Close()
   Return Content
}