Global Scripts & Properties in Indigo?

Posted on
Fri Apr 11, 2003 12:54 pm
sjmarbu offline
Posts: 11
Joined: Apr 08, 2003

Global Scripts & Properties in Indigo?

Does Indigo support Global Scripts? By that I mean an applescript that can be executed by any trigger? If so, how would such a script access state variables (applescript properties) that would be persistant and accessible from any script run within Indigo?

Background: I have a series of X10 actuated DPDT switches to route speaker signals between rooms. Each switch is represented by an X10 address and a Device in Indigo. Since the amplifier can only drive one set of speakers at a time, it is necessary to turn off the speaker pair that is currently on (the Indigo Device name needs to be stored in Indigo Variable currentSpeaker) and then turn on the desired speaker pair. So the name of the currently active speaker pair is available next time a speaker change is made, it is necessary to set currentSpeaker to the name of the new speaker pair.

I've tried to compile an external applescript using ScriptEditor, but since it doesn't have access to Indigo's variables, it won't compile. Yet an external script is the only kind I can figure that can be accessed from any Indigo trigger.

I suppose it is possible to use the same script for the ON of each trigger, but that's a maintenance nightmare if any changes are ever made to the script (imagine having to edit 12 speaker triggers and you begin to get the idea).

Any ideas?

Is there online documentation related to heavy duty applescripting with Indigo?

Is there a user manual somewhere?

Thanks,

Scot

Posted on
Fri Apr 11, 2003 3:59 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Global Scripts & Properties in Indigo?

sjmarbu wrote:
Does Indigo support Global Scripts? By that I mean an applescript that can be executed by any trigger? If so, how would such a script access state variables (applescript properties) that would be persistant and accessible from any script run within Indigo?

There are a couple of different techniques you could use for your speaker signal routing automation. I'd suggest we start by creating an AppleScript attachment script, which is a global script that Indigo will dispatch all X10 commands to automatically.

To store a global _currentSpeaker_ state you can either use an Indigo variable, which will persist across application runs and be accessible from all scripts, or you can use an AppleScript "property". In my example script below, I use an Indigo variable. To see an example of an AppleScript property in use, you can look for "currentVolume" in the _iTunes Attachment.scp_ attachment script located in your _Indigo User Data/Scripts/Attachment/_ folder.

Below is a link to a sample script I wrote that illustrates how to accomplish the mutually exclusive on states you need. It surely won't work exactly as I wrote it (I don't know what addresses your X10 switches are), but it should get you started. Take a look at it and let me know how it goes.

(6/2/2004 Update: Link to script removed. Attachment script architecture have changed a bit since version 1.0, so this script is now out-of-date.)

Note that the all attachment scripts get X10 received commands (AppleEvents) only (along with a power failure message, I believe). This means that the script will not get called, and thus will not provide any mutual exclusive behavior, if you manually turn on your X10 switches from within the main Indigo window. However, if you use a remote control, or any method that will end up causing any of your X10 interfaces to receive the command, then it will work.

Some notes on attachment scripts, such as the one above:

- They must live inside of your _user folder/Documents/Indigo User Data/Scripts/Attachments/_ folder. All attachment scripts in this folder will automatically be managed by Indigo. They will be sent AppleEvents based on X10 interface command reception, and will automatically be launched and quit in tandem with Indigo.

- They must be save as script "Applications". You should also choose the "Stay Open" and "Never Show Startup Screen" options from the script editor when initially creating the attachment file. For the adventurous -- these attachment plug-ins do not have to be AppleScripts. Any application that can receive AppleEvents can be placed into the attachments folder and will automatically be sent AppleEvents, and will automatically be launched and quit in tandem with Indigo.

sjmarbu wrote:
I've tried to compile an external applescript using ScriptEditor, but since it doesn't have access to Indigo's variables, it won't compile...

To access Indigo's internal AppleScript dictionary use the following line:

   using terms from application "Indigo"

sjmarbu wrote:
Is there online documentation related to heavy duty applescripting with Indigo?

Is there a user manual somewhere?

Although Indigo has a built-in Apple help book, the section on AppleScript only gives a brief overview of scripting. I believe it also points to this online forum. Circular reference, ehh? :-)

The AppleScript extensibility model (object model, dictionary, attachment model, etc.) is a work in progress. It does a great deal currently, but the key to providing all the functionality our users need will be based on requests and feedback. So you can expect to see new verbs, such as your previous Play Sound request, in future versions of Indigo. You can also expect to see more formal documentation on extensibility of Indigo in the future. In the mean time, you can use the Indigo dictionary documentation viewable from the Script Editor, the sample scripts that shipped with Indigo, and of course this forum, to help get you up and running.

Keep the good questions coming, Scot!

regards,
matt
Last edited by matt (support) on Wed Jun 02, 2004 4:26 pm, edited 1 time in total.

Posted on
Fri Apr 11, 2003 8:15 pm
sjmarbu offline
Posts: 11
Joined: Apr 08, 2003

(No subject)

Thanks, the example helps a lot. The syntax examples are good, but I'm still a little vague on how an attachment script can be called from within Indigo.

For example, I'd like to set up a Trigger Action for Address I6 that, when X10 command I6 is received, will execute an attachment script and pass it one or more parameters. Something like this would be nice to be able to do in the Embedded textarea of the Action:

setSpeakerOn( "SpeakerBedroom" )

And the attachment script would look something like:

on setCurrentSpeaker(speaker)
set currentSpeaker to speaker
end setCurrentSpeaker

on getCurrentSpeaker()
return currentSpeaker
end getCurrentSpeaker

on setOldSpeaker(speaker)
set oldSpeaker to speaker
end setOldSpeaker

on getOldSpeaker()
return oldSpeaker
end getOldSpeaker

on setSpeakerOn(newSpeaker)
if getOldSpeaker() is not equal to "" then
turnoff oldSpeaker
end if
if currentSpeaker is not equal to "" then
setOldSpeaker(currentSpeaker)
turnoff currentSpeaker
end if
setCurrentSpeaker(newSpeaker)
turnon newSpeaker
log newSpeaker & " ON, " & oldSpeaker & " OFF, currentSpeaker = " & getCurrentSpeaker() color green
end setSpeakerOn


The attachment script contains multiple methods, any of which can be accessed from within the embedded applescripts in Indigo, and from other attachment scripts. Also, the Indigo variables newSpeaker, currentSpeaker, and oldSpeaker can be set to hold references to Indigo devices, and actions can be taken on those devices in the script (for example, turn on newSpeaker would, if newSpeaker held a reference to Indigo device Kitchen Speaker, turn on the speaker in the kitchen).

Perhaps this is possible now but I'm at a loss as to how. I just tried a simple example where I created an attachment script called HelloWorld that consisted of:
using terms from application "Indigo"
tell application "Indigo"
log "Hello"
end tell
end using terms from

I saved it in the Attachments directory with the options you indicated, then attempted to access it from a Trigger Action Embedded script by just involking:
HelloWorld

I got the following message in the Event Log:
!! Script Error: The variable HelloWorld is not defined.

Maybe my syntax is foobared?

As a side comment, I'm not overly enamoured of reflecting my home control layout in a gui I can click with a mouse to get things to happen. All of my existing automation is triggered by wall switches or timed events, with perhaps one or two motion sensors. I seldom use the gui, and consider it a bad day if I have to fire up the monitor to see what's going on with the home control app. So I'd encourage you to focus your efforts on enabling scripting between Devices and Trigger Actions within Indigo.

Thanks for your efforts with Indigo, it sure shows a lot of potential!

Scot

Posted on
Tue Apr 15, 2003 4:24 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

sjmarbu wrote:
For example, I'd like to set up a Trigger Action for Address I6 that, when X10 command I6 is received, will execute an attachment script and pass it one or more parameters. Something like this would be nice to be able to do in the Embedded textarea of the Action:


In the attachment script I previously provided you, the script is handling everything. It listens to the low level X10 commands coming in, such as "I6 ON", and manages what actions to take based on that. Using this approach no Trigger Action within Indigo is needed at all.

It sounds like you want to specify an Indigo Trigger Action that executes embedded AppleScript that talks to an external attachment script. This approach should work, but on investigating it I just now found a bug where the main Indigo event loop is getting blocked by the OS. So for now, the approach of passing data from an Indigo Trigger Action into a scrip attachment (or any script) has some problems. The event loop blocking only happens when the attachment script tries to call back in to Indigo, but given your description I believe this will happen in your case. I'm investigating a solution to this.

Regardless of the blocking issue above, I think some comments on what attachment scripts are and how they work will help clarify some issues. Attachment scripts are special script applications that Indigo manages and dispatches some specific X10 AppleEvents to. There are 3 unique interactions Indigo has with an attachment script:

- Indigo automatically launches them on app start. Because of this they must be saved as AppleScript applications, and the "Stay Open" and "Never Show Startup Screen" options must be selected.

- Indigo automatically dispatches all X10 commands received by any X10 Interfaces (MR26, CM11, etc.) to the attachments. The list of AppleEvents and their parameters dispatched to the attachment can be found in the "Indigo PlugIn Suite" of the Indigo dictionary.

- Indigo automatically quits all attachments when the app shuts down.

Given this, you call handlers inside of an AppleScript attachment just like you would any other script. So the embedded AppleScript inside of a Trigger Action would look something like this:

tell application "Test Attachment"
  testHandler1("currentSpeaker")
end tell

Where the _Test Attachment_ script application (in the attachments folder) would look like:

on testHandler1(varName)
  tell application "Indigo"
    log "varName is " & varName
    log "varValue is " & (value of variable varName)
  end tell
end testHandler1

But with the bug described above, testHandler1() will get blocked on the log() call back to Indigo.

For now, you will need to stick with the do-it-all-in-the-attachment technique that I gave an example of previously. I'll continue to investigate solutions to the blocking bug and future alternative techniques.

regards,
matt

Posted on
Mon Apr 21, 2003 1:12 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Starting a new thread subject

We've made some changes that will greatly simplify creating global attachment scripts. Because the nature of these changes, I'm starting a new thread topic, "AppleScript plug-in changes in Indigo 1.1", to discuss them.

regards,
matt

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 29 guests