How to Use AppleScript to Display Logs in Indigo Touch

Posted on
Tue Aug 10, 2010 8:40 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

How to Use AppleScript to Display Logs in Indigo Touch

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.

Posted on
Fri Sep 03, 2010 12:38 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

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

That is very cool. Great idea.

Posted on
Sat Sep 04, 2010 10:00 am
hamw offline
Posts: 1212
Joined: Mar 31, 2008

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

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.
Last edited by hamw on Sun Jan 13, 2013 8:58 pm, edited 1 time in total.

Posted on
Mon Sep 06, 2010 7:22 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

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

Nice modification, hamw. Very handy to not have the time stamps all the time.

Posted on
Sat Sep 11, 2010 6:40 am
hamw offline
Posts: 1212
Joined: Mar 31, 2008

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

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?

Posted on
Sat Dec 18, 2010 10:55 am
hamw offline
Posts: 1212
Joined: Mar 31, 2008

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

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.

Posted on
Sat Dec 18, 2010 11:20 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

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

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Dec 18, 2010 2:18 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

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

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!

Posted on
Sun May 22, 2011 6:48 am
hamw offline
Posts: 1212
Joined: Mar 31, 2008

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

If you have upgraded to Indigo 5,change the Indigo 4 in the first line to Indigo 5. Will work fine.

Posted on
Sun May 22, 2011 8:42 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

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

I've updated the script in the original post with your suggestion. Thanks.

Image

Posted on
Sun Apr 27, 2014 8:51 pm
TheTechnoPilot offline
Posts: 46
Joined: Mar 31, 2014
Location: Montreal, QC, Canada

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

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"

Posted on
Thu Apr 21, 2016 10:38 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

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

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.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Fri Apr 29, 2016 11:08 am
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

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

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?

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun May 01, 2016 6:53 pm
Different Computers offline
User avatar
Posts: 2533
Joined: Jan 02, 2016
Location: East Coast

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

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?

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Mon May 02, 2016 1:08 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

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

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

Who is online

Users browsing this forum: No registered users and 8 guests