Python help for a total novice

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
User avatar
SpencerJRoberts
Posts: 256
Joined: Sun Dec 09, 2012 12:07 pm
Location: Mountain View, CA

Python help for a total novice

Post by SpencerJRoberts »

Hoping someone can help me get started here. I am a novice scripter, all I've ever used is Applescript (no formal programming background but I pick things up fairly quickly). I am trying to teach myself python, or at least as much python as I need to know to work with Indigo, but am having trouble just getting python to talk to Indigo. I have followed the steps outlined here http://www.perceptiveautomation.com/wik ... e_examples but am probably doing something wrong. When I go to type [indigo host -i] into the scripting shell I get the following

Code: Select all

Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'indigohost' is not defined
>>> 

If I can just get Python to talk to Indigo I'm confident I can hack my way through learning what I need to! Thanks in advance for any help!
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Python help for a total novice

Post by matt (support) »

From Terminal execute both these lines:

Code: Select all

echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.bashrc

echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.bash_profile
Then close the Terminal window and re-open it. Does it work?

Note there is an even easier way though -- select the Plugins→Open Scripting Shell menu item, then you can copy/paste in the lines from the tutorial.
Image
gtreece
Posts: 171
Joined: Mon Sep 26, 2011 6:01 pm

Re: Python help for a total novice

Post by gtreece »

I can confirm on my Lion machine, that it is only loading .bash_profile when a new terminal window opens, so the second command Matt posted is what I had to use.

I think you could also include the .bashrc file in your .bash_profile, to achieve the same results, but I just created the alias directly in .bash_profile.
User avatar
SpencerJRoberts
Posts: 256
Joined: Sun Dec 09, 2012 12:07 pm
Location: Mountain View, CA

Re: Python help for a total novice

Post by SpencerJRoberts »

Thanks Matt, that did work but now I still can't get a .py to talk to indigo. I've created a test.py on the desktop and entered this:

Code: Select all

indigohost -e '
indigo.device.toggle("TV Room")
'
and Python returns this:

Code: Select all

Traceback (most recent call last):
  File "/Users/Roberts/Desktop/test.py", line 1, in <module>
    indigohost -e
NameError: name 'indigohost' is not defined
>>> 
Sorry for the stupid questions :P
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Python help for a total novice

Post by matt (support) »

The 'indigohost' alias is just a shortcut so you can execute Indigo python commands from the Terminal (or a shell script). You don't want to call that from a .py script itself.

If you are wanting to make Indigo python API or object model calls from a .py script (like "indigo.device.toggle"), then that .py script has to be executed by Indigo as an Indigo action OR you can execute it from the shell using something like:

Code: Select all

indigohost -x /SomeFolder/indigo_script.py
That tells the indigo host process to launch and then run the .py file. Point being, Indigo .py files are special and have to be executed from Indigo or using the indigohost to work.
Image
User avatar
SpencerJRoberts
Posts: 256
Joined: Sun Dec 09, 2012 12:07 pm
Location: Mountain View, CA

Re: Python help for a total novice

Post by SpencerJRoberts »

Got it, that should be enough to get me started. Thanks so much!
User avatar
SpencerJRoberts
Posts: 256
Joined: Sun Dec 09, 2012 12:07 pm
Location: Mountain View, CA

Re: Python help for a total novice

Post by SpencerJRoberts »

Thanks again for the help, I'm loving learning Python! Quick question, is there still no way execute action groups or schedules from python? Thanks
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Python help for a total novice

Post by jay (support) »

Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
SpencerJRoberts
Posts: 256
Joined: Sun Dec 09, 2012 12:07 pm
Location: Mountain View, CA

Re: Python help for a total novice

Post by SpencerJRoberts »

Ah, I've been referencing this and must have missed that section, thanks!!
Locked

Return to “Extending Indigo with Plugins and Python”