Hello,

sorry to annoy you with a noobish question but I just don't understand what I 
am doing wrong...
I am relatively new to Python but its better than Applescript to me.
Can you please help me to get this right? How do I convert a string to the 
required "unicode_text" type wich is noth
the python builtin one. 
Reading the manual and google didn't help.
Your help would be very much appreciated.

Im using an Intel Macbook with Leopard 10.5.5, Python 2.5.1 and the newest 
appscript release.
You can find appscript on appscript.sourceforge.net.

I'm trying to do the following:
<python>
# coding: utf-8

from appscript import *
import random
import time

#start & open safari browser
safari= app('Safari')
safari.activate()
safari.document.URL.set("http://www.google.de";)

#wait for browser to open page
foo = 5 + int(random.random()*10)
time.sleep(foo)

#do some javascript manipulation on the loaded page
jscript= u"window.alert('foo');"

safari.do_JavaScript(jscript)
</python>


And this is the error message I am getting:
<error>
Traceback (most recent call last):
  File "scan.py", line 22, in <module>
    safari.do_JavaScript(jscript)
  File "/Library/Python/2.5/site-packages/appscript/reference.py", line 439, in 
__call__
    raise CommandError(self, (args, kargs), e)
appscript.reference.CommandError: CommandError -1700: Can't make some data into 
the expected type.
        Failed command: 
app(u'/Applications/Safari.app').do_JavaScript(u"window.alert('foo');")
</error>

Help says:
<help>
>>> safari.help('-t do_JavaScript')
==============================================================================
Help (-t do_JavaScript)

Reference: app(u'/Applications/Safari.app')

------------------------------------------------------------------------------
Terminology for do_JavaScript command

Command: do_JavaScript -- Applies a string of JavaScript code to a document.
  unicode_text -- The JavaScript code to evaluate.
  [in_ : tab] -- The tab that the JavaScript should be evaluated in.
  Result: anything



==============================================================================
</help>

Thank you very much in advance.

Yours Martin Tönnishoff
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to