Is This Convertible?

Posted on
Fri Nov 29, 2019 4:09 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Is This Convertible?

Hey,

I use a phone app called Dialectic to trigger actions in Indigo using an AS that is executed on an incoming call.

Code: Select all
(*

    This script will turn on a device controlled by Indigo when an incoming call is detected.

    For more information on Indigo, please see:

    http://www.perceptiveautomation.com/

    If you don't adjust the device_name property at the top o the script, you will be prompted for the
    device to turn on each time the script is triggered.

    *)


on handle_incoming_call_action(contact_name, contact_number, phone_or_modem_name)
   try
      tell application "IndigoServer"
         # Log the number so we can see what it is
         log "call from " & (contact_number as string)
         log "call from " & (contact_name as string)
         set the value of variable "CIDname" to (contact_name as string)
         set longPhoneNumber to contact_number
         set AppleScript's text item delimiters to "-"
         set shortPhoneNumber to (text items 2 thru -1 of longPhoneNumber) as text
         set the value of variable "CIDnumber" to shortPhoneNumber
         
      end tell
   on error the_error
      activate
      display dialog "Error: " & the_error buttons {"OK"} default button 1 with icon 0 giving up after 20
   end try
end handle_incoming_call_action



Can this be converted and possibly executed as an Automator app? Dialectic will only run an AS or launch an app on an incoming call.

Really appreciate any ideas.

Thanks,

Carl

Posted on
Sat Nov 30, 2019 8:54 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Is This Convertible?

It could be converted to an external python script that targets Indigo, but does Dialetic pass phone number etc to the external app/script like it does AS?


Sent from my iPhone using Tapatalk Pro

Posted on
Sat Nov 30, 2019 3:55 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Is This Convertible?

Take a look at the Indigo Control AppleScript. We made it for cases like this where you really need AppleScript to be able to communicate to Indigo Server running on the same Mac.

Once you copy/paste the contents of IndigoControl.applescript into the top of the script, you should be able to modify it like this to update the variables in Indigo:

Code: Select all
on handle_incoming_call_action(contact_name, contact_number, phone_or_modem_name)
   try
     set longPhoneNumber to contact_number
     set AppleScript's text item delimiters to "-"
     set shortPhoneNumber to (text items 2 thru -1 of longPhoneNumber) as text

     updateVariable_byName("CIDname", (contact_name as string))
     updateVariable_byName("CIDnumber", shortPhoneNumber)
   on error the_error
      activate
      display dialog "Error: " & the_error buttons {"OK"} default button 1 with icon 0 giving up after 20
   end try
end handle_incoming_call_action

Note I had to remove the Indigo log calls since there isn't a handler for that defined in IndigoControl.applescript. If you really want that logged in Indigo you could create Triggers in Indigo on variable value changed to catch when the values update then have the action in that Trigger log the current value.

Image

Posted on
Sat Nov 30, 2019 4:13 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Is This Convertible?

Ps - looks like the .applescript filecheck stops at iph72...


Sent from my iPad using Tapatalk Pro

Posted on
Sat Nov 30, 2019 4:16 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Is This Convertible?

Newer than that and the /usr/local/indigo/indigo-host file should exist (which is checked first).

Image

Posted on
Sat Nov 30, 2019 4:44 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Is This Convertible?

Ah!


Sent from my iPad using Tapatalk Pro

Posted on
Sun Dec 01, 2019 4:15 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Is This Convertible?

Thanks! Look forward to trying it out.

Carl

Posted on
Mon Dec 02, 2019 7:15 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Is This Convertible?

Lost here in how the script gets put together.

Code: Select all
(*

    This script will turn on a device controlled by Indigo when an incoming call is detected.

    For more information on Indigo, please see:

    http://www.perceptiveautomation.com/

    If you don't adjust the device_name property at the top o the script, you will be prompted for the
    device to turn on each time the script is triggered.

    *)

-- Internal functions for dispatching commands to Indigo's python scripting engine:
on _getIphPath()
   set iph to "/usr/local/indigo/indigo-host"
   set iph72 to "/Library/Application Support/Perceptive Automation/Indigo 7.2/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost"
   set iph7 to "/Library/Application Support/Perceptive Automation/Indigo 7/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost"
   set iph6 to "/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost"
   set iph5 to "/Library/Application Support/Perceptive Automation/Indigo 5/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost"
     tell application "System Events"
      if exists file iph then
         return iph
      else if exists file iph72 then
         return iph72
      else if exists file iph7 then
         return iph7
      else if exists file iph6 then
         return iph6
      else if exists file iph5 then
         return iph5
      else
         error "Indigo Server not installed"
      end if
      end tell
end _getIphPath

on _executeIphCommand(command)
   set iphPath to _getIphPath()
   do shell script quoted form of iphPath & " -e " & quoted form of command
end _executeIphCommand

on handle_incoming_call_action(contact_name, contact_number, phone_or_modem_name)
   try
      set longPhoneNumber to contact_number
      set AppleScript's text item delimiters to "-"
      set shortPhoneNumber to (text items 2 thru -1 of longPhoneNumber) as text
      
      updateVariable_byName("CIDname", (contact_name as string))
      updateVariable_byName("CIDnumber", shortPhoneNumber)
   on error the_error
      activate
      display dialog "Error: " & the_error buttons {"OK"} default button 1 with icon 0 giving up after 20
   end try
end handle_incoming_call_action


This attempt won't compile...doesn't like the "end tell" in the top section.

Appreciate any help,

Carl

Posted on
Tue Dec 03, 2019 10:44 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Is This Convertible?

Hi Carl,

Sorry, looks like there was a syntax problem with the if/else clause up there. I've corrected both the version in github as well as what you posted above, so if you just try copy/pasting out of your post into the script I think it will work.

Image

Posted on
Tue Dec 03, 2019 1:49 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Is This Convertible?

The script now seems to be running but am getting this error.

Thanks,

Carl
Attachments
0F01D533-4B1B-408A-A3A1-652BC7FCAD21.jpeg
0F01D533-4B1B-408A-A3A1-652BC7FCAD21.jpeg (44.49 KiB) Viewed 2661 times

Posted on
Tue Dec 03, 2019 2:15 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Is This Convertible?

Looks like you didn't copy the entire contents of the IndigoControl.appleScript file into your script. If you are just updating variables you don't have to get it all, but be sure and get the updateVariable_by* functions.

Image

Posted on
Tue Dec 03, 2019 8:17 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Is This Convertible?

Doh...that was it. Working great!

Many thanks,

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest