Display realtime log files automatically

May 26, '04 09:08:00AM

Contributed by: nhajratw

One of the tools I use for application development creates a new log file in a particular directory every time it is started. Normally, if I want to keep watching what's happening in the log, I have to do a tail -100f logfile_name in the Terminal. Attach this AppleScript to your log folder, and it will automatically open a terminal window "tailing" the logfile whenever a new one is created. Please note that this is my very first AppleScript, so there are probably better ways to do it. Have fun!

on adding folder items to this_folder after receiving these_items
  try
    repeat with i from 1 to number of items in these_items
      set this_item to item i of these_items
      
      tell application "Finder"
        set theName to the name of this_item as string
      end tell
      
      tell application "Terminal"
        activate
        do script with command ¬
         "/usr/bin/tail -100f '/path/to/your/logfiles/" & ¬
         theName & "';exit"
      end tell
    end repeat
  on error error_message number error_number
    if the error_number is not -128 then
      tell application "Finder"
        activate
        display dialog error_message buttons {"Cancel"} ¬
         default button 1 giving up after 120
      end tell
    end if
  end try
end adding folder items to
[robg adds: I haven't tested this, beyond making sure the script compiles, which it does.]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040521155336573