Page 1 of 3

How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Tue Aug 10, 2010 8:40 pm
by nsheldon
Example: How to Use AppleScript and Time/Date Actions to Show Recent Logs in Indigo Touch

Though this isn't as good as a built-in option to view recent log activity within the Indigo Touch app (and web interface), it does allow you to view the last 5 lines of the log (this is adjustable), updated every minute. Note that this will only work with Indigo Pro.

Here's how to set it up. Create a new Time/Date Action within the Indigo 4 Pro client with the following parameters:

    Name: Update Recent Activity Variables
    Time/Date Trigger tab:
      Time: Every 0 hours 1.00 minutes
      Date: Every 1 days
      Randomize by +/-: 0 minutes
      Starts on: (make sure the date here is the current date).
      CHECKED Suppress logging
      NOT CHECKED Auto delete after trigger
    Condition tab:
      Upon trigger do actions Always
    Actions tab:
      Type: Execute AppleScript
      Embedded
      Code: Select all
      set the ActivityLog to do shell script "tail -5 \"/Library/Application Support/Perceptive Automation/Indigo 5/Logs/indigo_log.txt\""
      set the TotalNumberOfLines to the count of paragraphs in the ActivityLog
      set the CurrentLine to 1
      repeat while the CurrentLine is less than or equal to the TotalNumberOfLines
          set the TextOfTheCurrentLine to paragraph CurrentLine of the ActivityLog
          set the variableName to ("RecentActivity" & CurrentLine) as string
          if not (variable variableName exists) then
              make new variable with properties {name:variableName, value:TextOfTheCurrentLine}
          else
              set the value of the variable variableName to the TextOfTheCurrentLine
          end if
          set the CurrentLine to (the CurrentLine + 1)
      end repeat

      NOT CHECKED Delay by ... minutes.

If you want more than 5 lines, simply change the "-5" after the "tail" command on the first line of the AppleScript to the number of lines (and corresponding "RecentActivity#" variables) you want.

Allow the trigger to run at least once (which should happen within a minute after clicking the OK button in the new Time/Date Action dialog). This will create a "RecentActivity#" variable for each of the lines of log data. You can then go into the Control Pages section and edit an existing page (or create a new one) and place a new Variable Value object for each line of the log anywhere you like on the page. The variables will be named "RecentActivity1" through "RecentActivity5" (or up to whatever number of lines you set above).

NOTE that text does not wrap on control pages, so be sure your control page is wide enough to show all of each line.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Fri Sep 03, 2010 12:38 pm
by hamw
That is very cool. Great idea.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sat Sep 04, 2010 10:00 am
by hamw
This will get rid of the date stamp, which takes up a lot of room on the variable output. Change character start, currently at 12, to 20 or so if you want to get rid of the time too.


Code: Select all
set the ActivityLog to do shell script "tail -9 \"/Library/Application Support/Perceptive Automation/Indigo 6/Logs/indigo_log.txt\""
set the TotalNumberOfLines to the count of paragraphs in the ActivityLog
set the CurrentLine to 1
repeat while the CurrentLine is less than or equal to the TotalNumberOfLines
    set stringTextOfTheCurrentLine to paragraph CurrentLine of the ActivityLog as string
    set TextOfTheCurrentLine to (characters 12 through -1 of stringTextOfTheCurrentLine as string)
    set the variableName to ("RecentActivity" & CurrentLine) as string
    if not (variable variableName exists) then
        make new variable with properties {name:variableName, value:TextOfTheCurrentLine}
    else
        set the value of the variable variableName to the TextOfTheCurrentLine
    end if
    set the CurrentLine to (the CurrentLine + 1)
end repeat


edited for Indigo 6.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Mon Sep 06, 2010 7:22 pm
by nsheldon
Nice modification, hamw. Very handy to not have the time stamps all the time.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sat Sep 11, 2010 6:40 am
by hamw
The other thing I did was add a button to the top of the control page to execute the time date action so that the log would update immediately instead of having to wait a minute.

Code: Select all
execute time date action "Update Recent Activity Variables"


Oddly I am occasionally getting a bunch of colons in the spaces between numbers and words. A reboot of the server fixes it. Are you seeing the same thing?

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sat Dec 18, 2010 10:55 am
by hamw
Here's an example:

1:1:::3:1:::4:0: :W:e:b:S:e:r:v:e:r: :I:n:d:i:g:o: :T:o:u:c:h: :c:l:i:e:n:t: :c:o:n:n:e:c:t:e:d: :f:r:o:m: :1:0:.:0:.:1:.:2:0:0

any thoughts as to why this would happen? Otherwise this is a great script.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sat Dec 18, 2010 11:20 am
by jay (support)
Add this line:

Code: Select all
set AppleScript's text item delimiters to ""


at the top of the script and see if that helps. The line that cuts out the date is reassembling the string by using text item replacements and you probably have another embedded script that periodically runs that's setting the delimiter to ":". That would cause what you're seeing. No guarantee but I suspect that's it.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sat Dec 18, 2010 2:18 pm
by hamw
Right you are, Jay. In my script for setting a timer variable for a whole house alarm clock, the set text item delimiter is there.
Code: Select all
using terms from application "IndigoServer"
    set theCurrentDateTime to absolute trigger time of time date action "Radio WakeUP Actual WakeUp Time"
    set AppleScript's text item delimiters to ":"
    set theTargetTime to value of variable "RadioWakeUpDisplay"
    set hours of theCurrentDateTime to (text item 1 of theTargetTime) as number
    set minutes of theCurrentDateTime to (text item 2 of theTargetTime) as number
    set absolute trigger time of time date action "Radio WakeUP Actual WakeUp Time" to theCurrentDateTime
    set the value of the variable "RadioWakeUpEnabled" to "Yes, Actual Time"
end using terms from


All fixed up!

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sun May 22, 2011 6:48 am
by hamw
If you have upgraded to Indigo 5,change the Indigo 4 in the first line to Indigo 5. Will work fine.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sun May 22, 2011 8:42 am
by matt (support)
I've updated the script in the original post with your suggestion. Thanks.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sun Apr 27, 2014 8:51 pm
by TheTechnoPilot
Hi all,

I updated this for the current daily log scheme that I am seeing in my copy of Indigo 6 and thought I would share it back out.

Code: Select all
set IndigoLogYear to (year of (current date))
set IndigoLogMonth to ((current date)'s month as integer) as number
if IndigoLogMonth < 10 then
   set IndigoLogMonth to "0" & IndigoLogMonth
end if
set IndigoLogDay to ((day of (current date)) & " Events.txt") as string
set IndigoLogName to (IndigoLogYear & "-" & IndigoLogMonth & "-" & IndigoLogDay) as string
log IndigoLogName

set the ActivityLog to do shell script "tail -10 \"/Library/Application Support/Perceptive Automation/Indigo 6/Logs/" & IndigoLogName & "\""
set the TotalNumberOfLines to the count of paragraphs in the ActivityLog
set the CurrentLine to 1
repeat while the CurrentLine is less than or equal to the TotalNumberOfLines
   set stringTextOfTheCurrentLine to paragraph CurrentLine of the ActivityLog as string
   set TextOfTheCurrentLine to (characters 12 through -1 of stringTextOfTheCurrentLine as string)
   tell application "IndigoServer"
      set the variableName to ("RecentActivity" & CurrentLine) as string
      if not (variable variableName exists) then
         make new variable with properties {name:variableName, value:TextOfTheCurrentLine}
      else
         set the value of the variable variableName to the TextOfTheCurrentLine
      end if
      set the CurrentLine to (the CurrentLine + 1)
   end tell
end repeat


Cheers,
Sean "TheTechnoPilot"

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Thu Apr 21, 2016 10:38 am
by Different Computers
I would love to modify this script to only pull trigger executions from the log. Would grep work for this? I'm not sure how the log formats the whole

Code: Select all
Trigger        this is where the trigger name goes


Thing.

Since I name my triggers something conversational, like "Kitchen lights turned off because no one is in there." I would love to just have those showing up on a control page.

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Fri Apr 29, 2016 11:08 am
by Different Computers
I got this working, though it's not pulling just triggers. That's OK.

In the scheduled run of this, I have logging suppressed, but I still get a log entry for "Script 2016-04-29 Events.txt" that's generated every minute. Is there a way to suppress that too?

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Sun May 01, 2016 6:53 pm
by Different Computers
So it's the first of the month, which I mention because this started just after midnight.

Error script error: tail: /Library/Application Support/Perceptive Automation/Indigo 6/Logs/2016-05-1 Events.txt: No such file or directory

The script still seems to be working though. Ideas how to fix it?

Re: How to Use AppleScript to Display Logs in Indigo Touch

PostPosted: Mon May 02, 2016 1:08 am
by howartp
The log file is 2016-05-01 so you need to pad the '1' with a '0' in your script.


Sent from my iPhone using Tapatalk