[Pythonmac-SIG] AppScripting Safari
John Weeks
john.weeks at insead.edu
Tue Jan 13 16:39:04 EST 2004
I am experimenting with AppScripting and Safari and I have a question
about how to translate the "do JavaScript" command into the form
AppScripting expects.
I have a AppleScript program that looks like this:
property timeout_value : 60
tell application "Safari"
activate
try
if not (exists document 1) then
make new document at the beginning of documents
end if
set the URL of the front document to "http://lexis-nexis.com/"
if my page_loaded(timeout_value) is false then error "Timed out"
end try
end tell
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
return true
else if i is the timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded
Using AppScripting, I can get this far:
from AppScripting import app, classes, enums, item
safari = app('Safari.app')
if not safari.windows[0].exists():
safari.documents.end.make(new=classes.document)
safari.windows[0].document.URL.set('http://lexis-nexis.com')
But then I am stumped. How to do I perform the do JavaScript?
Thanks,
John
More information about the Pythonmac-SIG
mailing list