View unanswered posts | View active topics It is currently Sat May 18, 2013 2:48 am



Reply to topic  [ 41 posts ]  Go to page: Previous  1, 2, 3  Next
 Help converting a simple applescript to Python 
Author Message
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11671
Location: Texas
Post Re: Help converting a simple applescript to Python
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


Tue Mar 27, 2012 9:01 am
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Re: Help converting a simple applescript to Python
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()))"


Tue Mar 27, 2012 9:20 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11671
Location: Texas
Post Re: Help converting a simple applescript to Python
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


Tue Mar 27, 2012 9:30 am
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Re: Help converting a simple applescript to Python
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


Tue Mar 27, 2012 9:56 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11671
Location: Texas
Post Re: Help converting a simple applescript to Python
How about just this single line script:

Code: Select all
indigo.variable.updateValue(862715057, "hello")

_________________
Image


Tue Mar 27, 2012 10:00 am
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Re: Help converting a simple applescript to Python
No joy, same error; invalid syntax. :?


Tue Mar 27, 2012 10:25 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11671
Location: Texas
Post Re: Help converting a simple applescript to Python
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


Tue Mar 27, 2012 10:48 am
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Re: Help converting a simple applescript to Python
Matt,

Won't compile even the first one;

script Error embedded script: invalid syntax
Script Error around line 1 - "foo = "hello""


Tue Mar 27, 2012 2:09 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11671
Location: Texas
Post Re: Help converting a simple applescript to Python
Try:

Code: Select all
foo = 5
indigo.server.log(str(foo))

_________________
Image


Tue Mar 27, 2012 2:21 pm
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Re: Help converting a simple applescript to Python
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)


Tue Mar 27, 2012 3:25 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11671
Location: Texas
Post Re: Help converting a simple applescript to Python
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


Tue Mar 27, 2012 3:33 pm
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Re: Help converting a simple applescript to Python
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()))


Tue Mar 27, 2012 3:56 pm
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6642
Location: Austin, Texas
Post Re: Help converting a simple applescript to Python
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)
Image


Tue Mar 27, 2012 4:53 pm
Profile WWW
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11671
Location: Texas
Post Re: Help converting a simple applescript to Python
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


Tue Mar 27, 2012 5:07 pm
Profile WWW
User avatar

Joined: Jun 14, 2006
Posts: 500
Post Re: Help converting a simple applescript to Python
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.


Tue Mar 27, 2012 5:36 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 41 posts ]  Go to page: Previous  1, 2, 3  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.