Help converting a simple applescript to Python

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
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Help converting a simple applescript to Python

Post by matt (support) »

That error shows that you have modified the script from what you originally posted.

Please try compiling the original script above again, then copy/paste any errors you see in the Event Log. Let's not change things while we are trying to troubleshoot -- it just makes everything more complicated for us.

And also copy/paste yet again *exactly* what you are compiling.
Image
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: Help converting a simple applescript to Python

Post by bob »

Matt,

Compiling this code from the previous post:

Code: Select all

#set coffee timestamp

import datetime
applianceLinc = indigo.devices["coffee"]
if applianceLinc.onState:
    indigo.variable.updateValue(862715057, str(datetime.datetime.now()))
Gives this in the log;
2012-03-27 9:18:59 AM
Script Error embedded script: invalid syntax
Script Error around line 6 - "indigo.variable.updateValue(862715057, str(datetime.datetime.now()))"
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Help converting a simple applescript to Python

Post by matt (support) »

Does this compile:

Code: Select all

applianceLinc = indigo.devices["coffee"]
if applianceLinc.onState:
    indigo.variable.updateValue(862715057, "hello")
And what version of OS X are you running?
Image
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: Help converting a simple applescript to Python

Post by bob »

Matt,

No it doesn't compile.
Script Error embedded script: invalid syntax
Script Error around line 3 - "indigo.variable.updateValue(862715057, "hello")"
OS X 10.7.2/Python 2.5.6/Indigo 5.0.4
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Help converting a simple applescript to Python

Post by matt (support) »

How about just this single line script:

Code: Select all

indigo.variable.updateValue(862715057, "hello")
Image
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: Help converting a simple applescript to Python

Post by bob »

No joy, same error; invalid syntax. :?
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Help converting a simple applescript to Python

Post by matt (support) »

Try:

Code: Select all

foo = "hello"
bar = "bye"
And then:

Code: Select all

foo = "hello"
bar = "bye"
indigo.server.log(foo)
And finally:

Code: Select all

foo = "hello"
bar = "bye"
indigo.variable.updateValue(862715057, foo)
indigo.variable.updateValue(862715057, bar)
Copy/paste the Event Log error results from all three.
Image
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: Help converting a simple applescript to Python

Post by bob »

Matt,

Won't compile even the first one;
script Error embedded script: invalid syntax
Script Error around line 1 - "foo = "hello""
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Help converting a simple applescript to Python

Post by matt (support) »

Try:

Code: Select all

foo = 5
indigo.server.log(str(foo))
Image
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: Help converting a simple applescript to Python

Post by bob »

Matt,

I'm at home on a different computer with the same versions of Indigo. This code:

Code: Select all

applianceLinc = indigo.devices["coffee"]
if applianceLinc.onState:
indigo.variable.updateValue(862715057, "hello")
gives this error now;
Error script error: around characters 16 to 23
Error script error: A unknown token can’t go after this identifier. (-2740)
this code;

Code: Select all

foo = "hello"
bar = "bye"
indigo.server.log(foo)
giver error:
Error script error: around characters 32 to 33
Error script error: Expected end of line, etc. but found unknown token. (-2741)
The last code you sent;

Code: Select all

foo = 5
indigo.server.log(str(foo))
gives this error:
Error script error: around characters 14 to 15
Error script error: Expected end of line, etc. but found unknown token. (-2741)
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Help converting a simple applescript to Python

Post by matt (support) »

Those are all AppleScript errors, which means you don't have python selected from the popup in the UI.

Also, make sure you have at least a space character indent on this line:

Code: Select all

indigo.variable.updateValue(862715057, "hello")
since Python requires it.
Image
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: Help converting a simple applescript to Python

Post by bob »

Matt,

OK, now it compiles with no errors in the log but it won't write the variable. I copied & pasted the new variable ID into the code so it is correct and the variable exists.

Code: Select all

import datetime
applianceLinc = indigo.devices["coffee"]
if applianceLinc.onState:
 indigo.variable.updateValue(717445627, str(datetime.datetime.now()))
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Help converting a simple applescript to Python

Post by jay (support) »

You still have a problem - the line after the "if" line needs to be indented by at least one space. Blocks in Python are delineated by indentation.

Code: Select all

import datetime
applianceLinc = indigo.devices["coffee"]
if applianceLinc.onState:
    indigo.variable.updateValue(717445627, str(datetime.datetime.now()))
4 spaces is generally considered standard form for Python.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Help converting a simple applescript to Python

Post by matt (support) »

It would be most helpful if you could explain what it is you changed to get it compiling -- it wasn't just the change from AppleScript to Python because your other posts on this forum thread are showing python errors, I believe. We've spent some time with you troubleshooting this and it would be good to know for other customers that might run across the same problem.
Image
User avatar
bob
Posts: 500
Joined: Wed Jun 14, 2006 7:55 am

Re: Help converting a simple applescript to Python

Post by bob »

Matt,

I truly appreciate all your help.

I didn't change anything to get it to compile, I have no idea why it is compiling. I just switched to a different computer (old mac pro) when I got home from work (new AirBook). Same OS X version, same Indigo version. Even though it compiles on this computer it won't write to the variable.

The line after the "if" is indented.
I tried changing to a new variable/ID but it still won't write and I don't get errors in the log.

I have no idea what to do.
Locked

Return to “Extending Indigo with Plugins and Python”