How to Use AppleScript to Display Logs in Indigo Touch

This subforum has been locked since we no longer support AppleScript.
nsheldon
Posts: 2469
Joined: Mon Aug 09, 2010 2:12 pm
Location: CA
Contact:

How to Use AppleScript to Display Logs in Indigo Touch

Post 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.
hamw
Posts: 1246
Joined: Mon Mar 31, 2008 7:45 pm

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

Post by hamw »

That is very cool. Great idea.
hamw
Posts: 1246
Joined: Mon Mar 31, 2008 7:45 pm

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

Post 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.
Last edited by hamw on Sun Jan 13, 2013 8:58 pm, edited 1 time in total.
nsheldon
Posts: 2469
Joined: Mon Aug 09, 2010 2:12 pm
Location: CA
Contact:

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

Post by nsheldon »

Nice modification, hamw. Very handy to not have the time stamps all the time.
hamw
Posts: 1246
Joined: Mon Mar 31, 2008 7:45 pm

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

Post 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?
hamw
Posts: 1246
Joined: Mon Mar 31, 2008 7:45 pm

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

Post 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.
User avatar
jay (support)
Site Admin
Posts: 18411
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

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

Post 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.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
hamw
Posts: 1246
Joined: Mon Mar 31, 2008 7:45 pm

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

Post 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!
hamw
Posts: 1246
Joined: Mon Mar 31, 2008 7:45 pm

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

Post by hamw »

If you have upgraded to Indigo 5,change the Indigo 4 in the first line to Indigo 5. Will work fine.
User avatar
matt (support)
Site Admin
Posts: 21476
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

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

Post by matt (support) »

I've updated the script in the original post with your suggestion. Thanks.
Image
TheTechnoPilot
Posts: 46
Joined: Mon Mar 31, 2014 9:16 pm
Location: Montreal, QC, Canada
Contact:

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

Post 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"
User avatar
Different Computers
Posts: 2609
Joined: Sat Jan 02, 2016 10:07 am
Location: East Coast
Contact:

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

Post 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.
Sonoma on a Mac Mini M1 running Airfoil Pro, Bond Home, Camect, Roku Network Remote, Hue Lights, DomoPad, Adapters, Home Assistant Agent, HomeKitLinkSiri, EPS Smart Dimmer, Fantastic Weather, Nanoleaf, LED Simple Effects, Grafana. UnifiAP
User avatar
Different Computers
Posts: 2609
Joined: Sat Jan 02, 2016 10:07 am
Location: East Coast
Contact:

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

Post 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?
Sonoma on a Mac Mini M1 running Airfoil Pro, Bond Home, Camect, Roku Network Remote, Hue Lights, DomoPad, Adapters, Home Assistant Agent, HomeKitLinkSiri, EPS Smart Dimmer, Fantastic Weather, Nanoleaf, LED Simple Effects, Grafana. UnifiAP
User avatar
Different Computers
Posts: 2609
Joined: Sat Jan 02, 2016 10:07 am
Location: East Coast
Contact:

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

Post 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?
Sonoma on a Mac Mini M1 running Airfoil Pro, Bond Home, Camect, Roku Network Remote, Hue Lights, DomoPad, Adapters, Home Assistant Agent, HomeKitLinkSiri, EPS Smart Dimmer, Fantastic Weather, Nanoleaf, LED Simple Effects, Grafana. UnifiAP
howartp
Posts: 4559
Joined: Thu Jan 09, 2014 4:43 pm
Location: West Yorkshire, UK

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

Post 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
Locked

Return to “AppleScript Scripting”