Help converting a simple applescript to Python
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
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
- 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
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.
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.
Re: Help converting a simple applescript to Python
Matt,
Compiling this code from the previous post:
Gives this in the log;
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()))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()))"
- 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
Does this compile:
And what version of OS X are you running?
Code: Select all
applianceLinc = indigo.devices["coffee"]
if applianceLinc.onState:
indigo.variable.updateValue(862715057, "hello")Re: Help converting a simple applescript to Python
Matt,
No it doesn't compile.
No it doesn't compile.
OS X 10.7.2/Python 2.5.6/Indigo 5.0.4Script Error embedded script: invalid syntax
Script Error around line 3 - "indigo.variable.updateValue(862715057, "hello")"
- 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
How about just this single line script:
Code: Select all
indigo.variable.updateValue(862715057, "hello")Re: Help converting a simple applescript to Python
No joy, same error; invalid syntax. 
- 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
Try:
And then:
And finally:
Copy/paste the Event Log error results from all three.
Code: Select all
foo = "hello"
bar = "bye"Code: Select all
foo = "hello"
bar = "bye"
indigo.server.log(foo)Code: Select all
foo = "hello"
bar = "bye"
indigo.variable.updateValue(862715057, foo)
indigo.variable.updateValue(862715057, bar)Re: Help converting a simple applescript to Python
Matt,
Won't compile even the first one;
Won't compile even the first one;
script Error embedded script: invalid syntax
Script Error around line 1 - "foo = "hello""
- 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
Try:
Code: Select all
foo = 5
indigo.server.log(str(foo))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:
gives this error now;
giver error:
gives this error:
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")this code;Error script error: around characters 16 to 23
Error script error: A unknown token can’t go after this identifier. (-2740)
Code: Select all
foo = "hello"
bar = "bye"
indigo.server.log(foo)The last code you sent;Error script error: around characters 32 to 33
Error script error: Expected end of line, etc. but found unknown token. (-2741)
Code: Select all
foo = 5
indigo.server.log(str(foo))Error script error: around characters 14 to 15
Error script error: Expected end of line, etc. but found unknown token. (-2741)
- 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
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:
since Python requires it.
Also, make sure you have at least a space character indent on this line:
Code: Select all
indigo.variable.updateValue(862715057, "hello")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.
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()))- 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
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.
4 spaces is generally considered standard form for Python.
Code: Select all
import datetime
applianceLinc = indigo.devices["coffee"]
if applianceLinc.onState:
indigo.variable.updateValue(717445627, str(datetime.datetime.now()))- 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
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.
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.
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.
