Page 4 of 5

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Wed Jan 14, 2015 9:07 am
by MaartenT
GlennNZ wrote:
http://forums.indigodomo.com/viewtopic.php?f=4&t=2927&start=15

Probably posted in the wrong older forum. But above is my modification of the first script for Yosemite that acts on received messages via iMessage and enables execution of action groups etc. Have updated it since this post enabling two way communication which is quite handy - ie. After an hours absence indigo sends a imessage listing on devices and asking if I want to turn them off - a yes reply turns them all off. Happy to post that - but a few triggers and variables with that one - if interested.

There appears to be a Yosemite issue with apple scripting which I though I had but appeared to be changes in Yosemite to imessaging given lack of defined alerts etc - anyhow the above script is for Yosemite and works really well so far.

Glenn


Thank you Glenn. I'll try to get this one working.

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Mon Jan 19, 2015 3:56 pm
by Alphaman
I've been working on this for a while, too, and think I must concur. My troubleshooting indicates that the -1708 error code indicates a missing handler. There's a nice list of handlers required by Messages in the Messages Dictionary. You must have a handler for each one of those, for example:

Code: Select all
on av chat started
end av chat started


...even if your code doesn't use AV Chat, that instance must be handled. When I went through and added all those various handlers, things started working again for this script.
It should be noted that the other sample scripts in the Messages Script folder aren't complete -- not even the iTunes script that this piece of code was built from. Running the iTunes script generated the same -1708 error we've been seeing here for me.
So, it seems to be not so much an issue of Yosemite being broken, but more strict about having all the handlers it needs than it used to be with Mavericks and earlier. I wonder if this is documented on the Developers' site -- I've not had a chance to go digging through that yet...

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Mon Jan 19, 2015 4:45 pm
by GlennNZ
I believe you are quite right.

The link below

http://forums.indigodomo.com/viewtopic.php?f=4&t=2927

- has all the handlers added - which is the main reason it works for Yosemite. There were also issues with different handlers if chat window open, closed, buddy selected etc.

Glenn

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sat Jan 24, 2015 8:20 am
by Seeker
confused.

does this work with yosemite?

I don't have a...

Put the script in the Library/Scripts/Messages folder in your user directory

...so where do i put this?

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sat Jan 24, 2015 1:16 pm
by GlennNZ
The link I posted above is working well in my Yosemite setup

Go to messages, preferences, script handlers, open directory and put it with all the others. Select it, change the buddy handle to allowed and away you go

Glenn

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sat Jan 24, 2015 7:30 pm
by Seeker
Thanks, found that.

Now, regarding

4. Create a new Apple ID with a new or otherwise unused email address and enable it in Messages.

does this really mean a new apple ID? or just an alias email account on my main ID?

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sat Jan 24, 2015 8:28 pm
by GlennNZ
Basically you need to be able to send iMessages from the indigo server (so need an account to do that) and this needs to be a seperate account.

My setup is with a standalone server - so I did create a appleID for the server - signed into imessage with that - can now send iMessages from the server. Need to check that works well before using the script.

Glenn

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sun Jan 25, 2015 10:39 am
by Seeker
Thanks Glenn and DVDDave,

I have it working with Yosemite with some basic action groups.

I have a new apple ID for my mini/indigo called 'indigo'. messages to this contact work as expected and control the scenes. But siri keeps trying to text the wrong address. I'll keep poking around with this.

edit, got my contacts straightened out. works great!

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sun Jan 25, 2015 12:48 pm
by DVDDave
Cool. Still chugging along for me too.

--Dave

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sat Feb 07, 2015 5:41 am
by mrmatt68
Here is what finally worked for me......change name to name of iMessage account name that is sending the message. Name the file Messages Indigo Control.scpt and save in application scripts....easiest way to get there is is messages menu then preferences then apple script handler then open scripts folder and create or place the file in there.

Code: Select all
(*

File: Messages Indigo Control.scpt

Abstract: This script is based on the iTunes Remote Control script which demonstrates the AppleScript "Message Received" handler for Messages. It will parse incoming messages and control Indigo in response.

Version: .1

*)

using terms from application "Messages"
   
   on replace_chars(this_text, search_string, replacement_string)
      set AppleScript's text item delimiters to the search_string
      set the item_list to every text item of this_text
      set AppleScript's text item delimiters to the replacement_string
      set this_text to the item_list as string
      set AppleScript's text item delimiters to ""
      return this_text
   end replace_chars
   
   on CapitalizeFirstLetter_ofEveryWord(InputString)
      set TheString to do shell script "echo " & InputString & " | tr '[A-Z]' '[a-z]'"
      set wordsofTheString to words of TheString as list
      set TotalCount to count of wordsofTheString
      set theCount to 1
      repeat until theCount is greater than TotalCount
         set theWord to item theCount of wordsofTheString
         set theChars to characters of theWord as list
         set Capital to item 1 of theChars
         set item 1 of theChars to do shell script "echo " & Capital & " | tr '[a-z]' '[A-Z]'"
         if theCount is less than TotalCount then
            set theWord to (theChars as string) & " "
         else
            set theWord to (theChars as string)
         end if
         set item theCount of wordsofTheString to theWord
         set theCount to theCount + 1
      end repeat
      set TheString to wordsofTheString as string
      return TheString
   end CapitalizeFirstLetter_ofEveryWord
   
   on trim_line(this_text, trim_chars, trim_indicator)
      -- 0 = beginning, 1 = end, 2 = both
      set x to the length of the trim_chars
      -- TRIM BEGINNING
      if the trim_indicator is in {0, 2} then
         repeat while this_text begins with the trim_chars
            try
               set this_text to characters (x + 1) thru -1 of this_text as string
            on error
               -- the text contains nothing but the trim characters
               return ""
            end try
         end repeat
      end if
      -- TRIM ENDING
      if the trim_indicator is in {1, 2} then
         repeat while this_text ends with the trim_chars
            try
               set this_text to characters 1 thru -(x + 1) of this_text as string
            on error
               -- the text contains nothing but the trim characters
               return ""
            end try
         end repeat
      end if
      return this_text
   end trim_line
   
   on getIndigoVariable(IndigoVariable)
      tell application "IndigoServer"
         set theVariableValue to get value of variable IndigoVariable
      end tell
      return theVariableValue
   end getIndigoVariable
   
   on setIndigoVariable(IndigoVariable, VariableValue)
      tell application "IndigoServer"
         set value of variable IndigoVariable to VariableValue
         set theVariableValue to get value of variable IndigoVariable
      end tell
      return "Variable set to " & theVariableValue
   end setIndigoVariable
   
   on executeIndigoAction(IndigoAction)
      tell application "IndigoServer"
         execute group IndigoAction
      end tell
      return "Action " & IndigoAction & " Executed"
   end executeIndigoAction
   
   on turnonIndigoDevice(IndigoDevice)
      try
         tell application "IndigoServer"
            turn on IndigoDevice
         end tell
         return IndigoDevice & " was told to turn on"
         
      on error
         return "error turning on " & IndigoDevice
      end try
   end turnonIndigoDevice
   
   on turnoffIndigoDevice(IndigoDevice)
      try
         tell application "IndigoServer"
            turn off IndigoDevice
         end tell
         return IndigoDevice & " was told to turn off"
      on error
         return "error turning off " & IndigoDevice
      end try
   end turnoffIndigoDevice
   
   -- handler to respond to all incoming messages.
   on runIndigoRemoteControl(theMessage)
      try
         
         -- use default "unknown" command, just in case.
         set theResponse to "Unknown command."
         set theMessage to trim_line(theMessage, "to ", 0)
         set theMessage to replace_chars(theMessage, "the ", "")
         
         if theMessage contains "status" then
            set theResponse to "Alive and Well!"
            
         else if theMessage is "arm alarm" then
            
            set theResponse to setIndigoVariable("AlarmArmed", "true")
            
         else if theMessage is "disarm alarm" then
            
            set theResponse to setIndigoVariable("AlarmArmed", "false")
            
         else if theMessage contains "raise heat" or theMessage contains "lower AC" or theMessage contains "raise temperature" then
            
            set theResponse to executeIndigoAction("Thermostat Higher")
            
         else if theMessage contains "lower heat" or theMessage contains "raise AC" or theMessage contains "lower temperature" then
            
            set theResponse to executeIndigoAction("Thermostat Lower")
            
         else if theMessage starts with "turn on" then
            
            set targetDevice to CapitalizeFirstLetter_ofEveryWord(trim_line(theMessage, "turn on ", 0))
            
            set theResponse to turnonIndigoDevice(targetDevice)
            
         else if theMessage starts with "turn off" then
            
            set targetDevice to CapitalizeFirstLetter_ofEveryWord(trim_line(theMessage, "turn off ", 0))
            
            set theResponse to turnoffIndigoDevice(targetDevice)
            
         else if theMessage starts with "execute" then
            
            set targetAction to trim_line(theMessage, "execute ", 0)
            set targetAction to trim_line(targetAction, "action ", 0)
            set targetAction to trim_line(targetAction, "group ", 0)
            set targetAction to CapitalizeFirstLetter_ofEveryWord(targetAction)
            
            set theResponse to executeIndigoAction(targetAction)
            
         else if theMessage is "help" then
            
            -- display available commands on "help"
            set theResponse to "Available commands: status, Turn on or off device, Raise or lower temperature, Arm or disarm alarm, Execute action"
            
         end if
         
         return theResponse
      on error
         return "Error processing message " & theMessage
      end try
   end runIndigoRemoteControl
   
   -- 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
      if full name of theBuddy is "Matthew A. Morgano" or full name of theBuddy is "Matthew A. Morgano" then
         accept theChat
      end if
      send "Welcome to Indigo Remote Control. " & runIndigoRemoteControl("help") 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
      
      if full name of theBuddy is "Change Name here" or full name of theBuddy is "Change Name Here" then
         
         set theResponse to runIndigoRemoteControl(theMessage)
         
         -- send back the response.      
         send theResponse to theChat
      end if
      
   end message received
   
   --locally test commands
   display dialog "Send a command to Indigo Remote Control:" default answer "status"
   set theMessage to the text returned of the result
   set theResponse to runIndigoRemoteControl(theMessage)
   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
      
   end chat room message received
   
   on active chat message received theMessage
      
   end active chat message received
   
   on addressed chat room message received theMessage from theBuddy for theChat
      
   end addressed chat room message received
   
   on addressed message received theMessage from theBuddy for 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

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sun Feb 22, 2015 8:11 am
by mrmatt68
Hi again,

I can get this working but only if i leave the preferences window open and applescript handler set to indigo control.....as soon as i close the window iMessage no longer works.....do i have to set that script a different way so that it'll be permanent? it always defaults to none no matter what script i choose. Do I have it in the wrong folder?

Matt

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sun Feb 22, 2015 9:45 am
by DVDDave
Hi Matt,

What you are doing should work. When you bring up preferences after closing it, is the script still selected? If not, maybe try repairing disk permissions or trashing the Messages pref file.

--Dave

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Mon Mar 30, 2015 3:20 pm
by Alain
Hi,
Trying to get this very cool system going...

I'm not able to get incoming messages to have Indigo react.
I have been able to get the script to "stick" in the preferences pane (applescript handler).
If I run the script within the script editor and give it a command, I can turn on a device in Indigo.
But if I send a message with the same command, nothing happens (I see it in the Messages app, but it seems like the script is not kicking in).
I have placed the file according to the instructions (located via the preferences dialog).

Anything I should try?

Thank you
Alain

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sat Apr 18, 2015 1:30 pm
by noel1983
Hi all,
Really keen to get this working however i'm stuck at the script stage never mind the iMessage bit. I've downloaded the latest script (I think) from above in this thread. opening it in script editor and running it I'm trying status, that works and responds alive and well.

If I run and type 'turn on bed' then I get 'error turning on bed'

I'm sure i've had this working before but then came across the errors everyones mentioned so parked it for a while and have come back to find the updated scripts.

I've confirmed that a standalone applescript can turn on bed ok but not the Messages Indigo Control Script sample.scpt file I have.

Any suggestions please?

Thanks
Noel

Re: iMessage/Messages/Siri Indigo Control Script

PostPosted: Sun Apr 26, 2015 4:54 am
by mrmatt68
Mine will work sometimes and sometimes not and i don't understand why. I wish i could help more because it is nice when it works. I wish indigo would build this functionality in or at least develop the plugin further.

Matt