View unanswered posts | View active topics It is currently Sun May 19, 2013 11:46 am



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

Joined: Jan 27, 2003
Posts: 11682
Location: Texas
Post Re: Help converting a simple applescript to Python
Okay, so it still doesn't work on the original Mac then. I'm not sure what could be different. Have you installed anything python related on that system?

For the updating problem, try each one of these lines individually (and by themselves -- no IF conditional) to see which ones work (and copy/paste any errors you see):

Code: Select all
indigo.variable.updateValue(717445627, "foo1")


Code: Select all
indigo.variable.updateValue("yourVariableNameHere", "foo2")


Code: Select all
import datetime
indigo.variable.updateValue("yourVariableNameHere", str(datetime.datetime.now()))

_________________
Image


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

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

I'll get back to you when I next get a chance to work on this. I don't have as much time for this as I used to. I thought starting with a simple script was going to be easy. Anyway.... thanks much for your assistance and if I stumble upon the solution in the meantime I'll be sure to post it. I'll get back to you with the results of your test when I can.

best,

bob


Tue Mar 27, 2012 9:44 pm
Profile
User avatar

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

OK I found something. This is what I have found so far;

Yesterday on the airbook I overwrote the trigger's applescript with the python script and got errors when I tried to compile it (I did select it to a python script). This morning I made a new trigger with everything the same but as it was a new trigger it did not previously have an applescript. I pasted in the python script and bingo it worked as advertised. (this is on a database imported from 4.0)

Next I created a new empty 5.0 database and made a trigger with an applescript. I then overwrote the applescript with a python script and it worked OK.

From this it looks like if you have an imported database from 4.0, a trigger can stay stuck on applescript if you try to change it to a python script. I tried duplicating the script then pasting in the python script but I got the same error. I had to create a new trigger to get it to work. I am going to try this on other triggers with applescripts.


Wed Mar 28, 2012 7:11 am
Profile
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6642
Location: Austin, Texas
Post Re: Help converting a simple applescript to Python
Just wanted to point out that I suggested that you delete the old action and create a new one back on my last post on the first page of the thread. That would have solved the problem.

We can't stress enough that following our guidance EXACTLY will always be the fastest path to problem resolution.

_________________
Jay (Indigo Support)
Image


Wed Mar 28, 2012 8:52 am
Profile WWW
User avatar

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

Sorry, I guess I missed that.

Why is it necessary to delete the Action? Is it only when changing from an Applescript to a Python script that this is necessary? Is the Applescript not being completely overwritten in the database when you switch to a Python script?


Wed Mar 28, 2012 9:12 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11682
Location: Texas
Post Re: Help converting a simple applescript to Python
It shouldn't be necessary. We aren't able to reproduce the problem, so if you can provide steps and an example AppleScript that does that would be helpful.

_________________
Image


Wed Mar 28, 2012 9:14 am
Profile WWW
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6642
Location: Austin, Texas
Post Re: Help converting a simple applescript to Python
To be honest it was a way to ensure that all of the text in the script area actually did get deleted. When we tell someone to replace the text in an area they don't always make sure that EVERYTHING in the area is gone. I suspect this was your problem all along - you just didn't get all the text (perhaps there was some unprintable character or something that got into it accidentally or a leftover from the AppleScript). When replacing text in a text field, it's always recommended that you do a Command-A - which will select everything (including unprintable characters) and then hit delete. That ensures that the area is completely empty.

It shouldn't be necessary to do the action delete/create - we completely replace the text from the dialog in the database when it's saved. It's possible there's a bug in that dialog - which is why we need a way to reproduce the problem.

_________________
Jay (Indigo Support)
Image


Wed Mar 28, 2012 11:52 am
Profile WWW
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11682
Location: Texas
Post Re: Help converting a simple applescript to Python
We've found steps that reproduce the problem and will have it fixed in Indigo 51.0. The workaround is to simply select all and press delete when switching between AppleScript and Python script types.

_________________
Image


Wed Mar 28, 2012 3:05 pm
Profile WWW
User avatar

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

For some reason I didn't get notification of your reply but anyway I a happy you found the problem.

I am trying to execute this script;

Code: Select all
import xml.etree.cElementTree as ET

#location of the file to be parsed
content = ET.ElementTree(file="/Users/abook/Desktop/tempalert.xml")

ports = content.find("ports")

#get all the port elements
for port in ports.findall('port'):
   
    if port.get('name') == 'Port 1':

        currentTemp = port.find("condition/currentReading")
        #print currentTemp.text
        indigo.variable.updateValue("tempAlert1_", currentTemp)

    elif port.get('name') == 'Port 2':

        currentTemp = port.find("condition/currentReading")
        #print currentTemp.text       
        indigo.variable.updateValue("tempAlert2_", currentTemp)


But I get this error;

$ indigohost -x /Users/abook/Desktop/workingcopy.py
workingcopy.py: invalid syntax
around line 1 - "import xml.etree.cElementTree as ET"



But if I run this below it runs OK.

Code: Select all
import xml.etree.cElementTree as ET

#location of the file to be parsed
content = ET.ElementTree(file="/Users/abook/Desktop/tempalert.xml")

ports = content.find("ports")

#get all the port elements
for port in ports.findall('port'):
   
    if port.get('name') == 'Port 1':

        currentTemp = port.find("condition/currentReading")
        print currentTemp.text
        #indigo.variable.updateValue("tempAlert1_", currentTemp)

    elif port.get('name') == 'Port 2':

        currentTemp = port.find("condition/currentReading")
        print currentTemp.text       
        #indigo.variable.updateValue("tempAlert2_", currentTemp)


Code: Select all
$ python /Users/abook/Desktop/workingcopy.py
73.2
950.2


Fri Mar 30, 2012 2:24 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11682
Location: Texas
Post Re: Help converting a simple applescript to Python
This is the same problem. The line endings on your .py file are probably Mac (CR+LF) but should be Unix (LF only).

_________________
Image


Fri Mar 30, 2012 2:39 pm
Profile WWW
Site Admin
User avatar

Joined: Mar 19, 2008
Posts: 6642
Location: Austin, Texas
Post Re: Help converting a simple applescript to Python
Most good text editors will fix it for you based on the file type.

BTW, it compiles fine for me:

Code: Select all
FatMac:temp jay$ indigohost -x ./test.py
test.py: [Errno 2] No such file or directory: '/Users/abook/Desktop/tempalert.xml'
Exception Traceback (most recent call shown last):

     test.py, line 4, at top level
     File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xml/etree/ElementTree.py", line 546, in __init__
       self.parse(file)
     test.py, line 21, in parse
IOError: [Errno 2] No such file or directory: '/Users/abook/Desktop/tempalert.xml'


It compiled fine and only threw when it ran and couldn't find your xml file on my system.

_________________
Jay (Indigo Support)
Image


Fri Mar 30, 2012 2:46 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 41 posts ]  Go to page: Previous  1, 2, 3

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.