Talk to Indigo via IChat on Leopard

Posted on
Tue Apr 05, 2011 12:53 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

Re: Talk to Indigo via IChat on Leopard

From the usage example in the script:
Code: Select all

set theResponse to "Available Commands: flash, bedtime, tail log,turn on/off [device],



I don't see it either, so I assumed it must have been handled by the last else block, which seems to just pass thru what you say:

Code: Select all
else
            tell application "IndigoServer"
               set result to (run script theMessage) as string
            end tell


If the quoting was correct somehow that would allow you to just pass thru applescript to indigo (just the turn on portion as we're already inside of a tell block):

Code: Select all
-- tell application "IndigoServer"
turn on "Office Lamp"
-- end tell


The later versions hard code all of this in else statements, which is simple but less elegant and means you need to update the script with all of your devices and add to it when you add new ones. It would be much nicer to just pass applescript thru if possible.

Posted on
Tue Apr 05, 2011 1:18 pm
jay (support) offline
Site Admin
User avatar
Posts: 15595
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Talk to Indigo via IChat on Leopard

You can include quotes in strings by escaping them with a backslash (\). So you can put a script into a string even if the script needs quoted strings. So this, for instance, works:

Code: Select all
set theScript to "tell application \"IndigoServer\" to turn on \"Office Light\""
run script theScript

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Apr 05, 2011 3:44 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

Re: Talk to Indigo via IChat on Leopard

We're still missing each other. :)

What I'm getting at is not hard coding it into the script, but just passing thru applescript from the IM session to Indigo.

So in an IM window I write: turn on office light

That's applescript syntax for Indigo. The problem is the *turn on* portion needs to be unquoted and the *office light* portion needs to be quoted as far as I can tell.

But even if in the IM session I write: turn on "office light"

It still fails with errors. Same goes for any escaping syntax I've tried.

This may well just be impossible.

Thanks,

-Chris

Posted on
Tue Apr 05, 2011 4:54 pm
jay (support) offline
Site Admin
User avatar
Posts: 15595
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Talk to Indigo via IChat on Leopard

Looked at the script more closely - the problem is that "run script" executes the script in the context of the script it's run from - regardless of the fact that it's inside a tell to "InsigoServer". So, the script doesn't understand what "turn on "Office Lamp"" means.

You need to add the targeting information to the passed in script before you try running it. Here's the modified "else":

Code: Select all
         else
            set theCommand to "tell application \"IndigoServer\"" & return & theMessage & return & "end tell"
            set result to (run script theCommand) as string
            
            if result is "" then
               set theResponse to "Executing " & theMessage
            else
               set theResponse to result
            end if
         end if



That produces the following:

Code: Select all
tell application "IndigoServer"
turn on "Office Lamp"
end tell


That should work if you type this into your chat client:

Code: Select all
turn on "Office Lamp"


Note - it's a bit dangerous allowing people to execute random AppleScripts on your server.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Apr 05, 2011 5:03 pm
chrisla23 offline
Posts: 97
Joined: Sep 16, 2009

Re: Talk to Indigo via IChat on Leopard

Thanks!

Once again you guys provide far better support than we pay 100's of thousands to the big guys at work for various things.

I'll give it a shot.

On the security front, I'm running OSX server that has built in iChat/Jabber server locally, so I'm using that. I could probably also bake in the basic username sanity checking someone else mentioned.

I'll test it out and re-post the whole thing here.

-Chris

Posted on
Thu Feb 13, 2014 1:37 pm
robertgerman offline
Posts: 42
Joined: Dec 14, 2013
Location: Vaxjo, Sweden

Re: Talk to Indigo via IChat on Leopard

Hi Guys,
just found this awesome way to get status reports. What I want to do is to send a iChat message when recieving a message in iChat. I want to send variable values but I am doing something wrong, this is what I have tried so far:

Code: Select all
set peopleICareAbout to {"Some dude"}

tell application "iChat"
   repeat with myBuddy in buddies
      --get properties of myBuddy
      if full name of myBuddy is in peopleICareAbout then
         send "Altandörren:  \ & " value of variable \"Altandorren\"" to myBuddy
      end if
   end repeat
end tell


Doesn't work, any suggestions? I can get iChat to send a message, but not with the value of a variable :-/

Rob

Posted on
Thu Feb 13, 2014 3:11 pm
jay (support) offline
Site Admin
User avatar
Posts: 15595
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Talk to Indigo via IChat on Leopard

You have to get the variable from Indigo first - your "value of variable" is still in the tell to iChat, which knows nothing about Indigo variables. You could just add the tell to Indigo right before the tell to iChat:

Code: Select all
set peopleICareAbout to {"Some dude"}

tell application "Indigo Server" to set varValue to value of variable "Altandorren"

tell application "iChat"
   repeat with myBuddy in buddies
      --get properties of myBuddy
      if full name of myBuddy is in peopleICareAbout then
         send "Altandörren: " & varValue to myBuddy
      end if
   end repeat
end tell


Not tested but it should be close.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 13, 2014 3:16 pm
robertgerman offline
Posts: 42
Joined: Dec 14, 2013
Location: Vaxjo, Sweden

Re: Talk to Indigo via IChat on Leopard

Thanks, my knowledge of AppleScript is really non existing, I get this error when running the script: Expected end of line, etc. but found """

Error is pointing to the first " in "Altandorren"

Posted on
Thu Feb 13, 2014 3:54 pm
jay (support) offline
Site Admin
User avatar
Posts: 15595
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Talk to Indigo via IChat on Leopard

Sorry, no space between "Indigo" and "Server".

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 13, 2014 3:56 pm
robertgerman offline
Posts: 42
Joined: Dec 14, 2013
Location: Vaxjo, Sweden

Re: Talk to Indigo via IChat on Leopard

Thanks! That did it :-)

Posted on
Thu Jan 01, 2015 11:01 pm
GlennNZ offline
Posts: 617
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: Talk to Indigo via IChat on Leopard

Thanks for Indigo

Digging up this script to post some changes for Yosemite - or at least I think changes for Yosemite.

Took a while to sort out - as depends whether chat window open or not as to the handler involved, which was giving timeout error until recognised.

Posted below the full script - simple changes to Itunesremote script, but very much the first script (thanks!), with Jays addition as above enabling turn on/off, execute etc.

Have also added allowed email addresses - or buddy handles - to limit access.

Yet to test extensively but appears to be working well in Yosemite currently.

Code: Select all
(*

File: Indigio Remote Control.applescript


*)

using terms from application "Messages"
   
   
   -- handler to respond to all incoming messages.
   on runiTunesRemoteControl(theMessage, theBuddy)
      if theBuddy is not equal to "testemail@gmail.com" then
         set theBuddy to theBuddy's handle
         (*
change the below email address to those allowed and decide response to those not allowed
*)
         set Allowed to 0
         if theBuddy is equal to "changetoallowedemail@email.com" then
            set Allowed to 1
         end if
         if theBuddy is equal to "changetoallowedemail@email.com" then
            set Allowed to 1
         end if
         if Allowed is equal to 0 then
            set theResponse to "Bugger off - access not allowed"
            return theResponse
         end if
      end if
      
      try
         if theMessage is "flash" then
            tell application "IndigoServer"
               flash(2)
            end tell
            set theResponse to "Executing flash"
         else if theMessage is "bedtime" then
            tell application "IndigoServer"
               execute group "scene - bedtime"
            end tell
            set theResponse to "Executing bedtime scene"
         else if theMessage is "tail log" then
            tell application "IndigoServer"
               set theResponse to build event log list line count 30
            end tell
         else if theMessage is "help" then
            -- display available commands on "help"
            set theResponse to "Available Commands: flash, bedtime, tail log, turn on/off [device], toggle [device], dim/brighten [device], all lights on/off, execute group [name], tail log, send email to [emailAddress] [with subject text] [with body text]"
         else
            set theCommand to "tell application \"IndigoServer\"" & return & theMessage & return & "end tell"
            set result to (run script theCommand) as string
            
            if result is "" then
               set theResponse to "Executing " & theMessage
            else
               set theResponse to result
            end if
         end if
      on error errorMessage
         set theResponse to errorMessage
      end try
      
      
      return theResponse
      
   end runiTunesRemoteControl
   
   -- When first message is received, accept the invitation and send a greeting message from iTunes Remote Control.
   on received text invitation theMessage from theBuddy for theChat
      accept theChat
      send "Welcome to Indigo Remote Control." to theChat
      set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
      send theResponse to theChat
   end received text invitation
   
   -- On subsequent messages, pass the message directly to iTunes Remote Control.
   on message received theMessage from theBuddy for theChat
      
      -- run the iTunesRemoteControl parser.
      set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
      
      -- send back the response.      
      send theResponse to theChat
      
   end message received
   
   -- Sample, so you can test run this through Script Editor.
   display dialog "Send a command to Indigo Remote Control:" default answer "status"
   set theMessage to the text returned of the result
   set theTestBuddy to "testemail@gmail.com"
   
   set theResponse to runiTunesRemoteControl(theMessage, theTestBuddy)
   display dialog theResponse
   
   # The following are unused but need to be defined to avoid an error
   
   on received audio invitation theText from theBuddy for theChat
      
   end received audio invitation
   
   on received video invitation theText from theBuddy for theChat
      
   end received video invitation
   
   on received remote screen sharing invitation from theBuddy for theChat
      
   end received remote screen sharing invitation
   
   on received local screen sharing invitation from theBuddy for theChat
      
   end received local screen sharing invitation
   
   on received file transfer invitation theFileTransfer
      
   end received file transfer invitation
   
   on buddy authorization requested theRequest
      
   end buddy authorization requested
   
   on message sent theMessage for theChat
      
   end message sent
   
   on chat room message received theMessage from theBuddy for theChat
      
      -- run the iTunesRemoteControl parser.
      set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
      
      -- send back the response.      
      send theResponse to theChat
      
   end chat room message received
   
   on active chat message received theMessage from theBuddy for theChat
      
      -- run the iTunesRemoteControl parser.
      set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
      
      -- send back the response.      
      send theResponse to theChat
      
   end active chat message received
   
   on addressed chat room message received theMessage from theBuddy for theChat
      
      -- run the iTunesRemoteControl parser.
      set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
      
      -- send back the response.      
      send theResponse to theChat
      
   end addressed chat room message received
   
   on addressed message received theMessage from theBuddy for theChat
      
      -- run the iTunesRemoteControl parser.
      set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
      
      -- send back the response.      
      send theResponse to theChat
      
   end addressed message received
   
   on av chat started
      
   end av chat started
   
   on av chat ended
      
   end av chat ended
   
   on login finished for theService
      
   end login finished
   
   on logout finished for theService
      
   end logout finished
   
   on buddy became available theBuddy
      
   end buddy became available
   
   on buddy became unavailable theBuddy
      
   end buddy became unavailable
   
   on completed file transfer
      
   end completed file transfer
   
end using terms from

Posted on
Mon Jan 19, 2015 11:59 am
mrmatt68 offline
Posts: 45
Joined: Nov 07, 2014

Re: Talk to Indigo via IChat on Leopard

How do i get this to work? I only get a bugger off response no matter what email or buddy name i put in.

Thanks

Posted on
Mon Jan 19, 2015 2:48 pm
GlennNZ offline
Posts: 617
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: Talk to Indigo via IChat on Leopard

I suspect it will be because your BuddyHandle is something other than your email.

Could try checking BuddyHandle in Applescript window or change the code below to that I've attached - just change the Bugger Off line

This should tell you to bugger off and then let you know what your Buddy Handle is - change the allowedemail to this.


Code: Select all
         if Allowed is equal to 0 then
            set theResponse to "Bugger off - access not allowed" & "BuddyHandle is " & theBuddy
            return theResponse
         end if



Glenn

Posted on
Fri Apr 17, 2015 1:59 pm
mabrown offline
User avatar
Posts: 39
Joined: Dec 08, 2012

Re: Talk to Indigo via IChat on Leopard

What's the syntax for issuing commands? I've tried turn off office lights, office lights being the lights in my office and I always get Expected end of line but found identifier. tail log and help works but that's about all I can get going. Running 10.10.3.

Who is online

Users browsing this forum: No registered users and 2 guests