After much research, I found out that Safari and OSX 10.3.9 updates changes some things. I’m not sure what, but some javaScript commands no longer work with applescript and safari. One is the command that puts data in a web form field.
do JavaScript "window.document.forms=[0].elements=qu.value='" & formValue & "';" in document 1
This no longer puts a value in the field. Does anybody know why apple did this to us and any fix around it?
I found out that most of my safari applescripts broke in Safari 1.3 and I am pretty mad at Apple for not documenting this (in a clear manner, before upgrading)
Not being an Javascripter, I am afraid cannot help you.
If you figure out anything as to what has been changed, please post some/any reference.
This works for me in Safari 2.0 (functionally identical to 1.3). Adjust the form & element indices to match the form and element of the page you are targeting, of course.
set formValue to "myValue"
tell application "Safari" to do JavaScript "document.forms[0].elements[0].value='" & formValue & "';" in document 1
Jon
Model: PowerBook 1.25MHz
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)
Me too my scripts are totally screwed!!!
Arrrgghhh!!
here’s an example of mine:
tell application “Safari” to set allLinks to ¬
do JavaScript “for (i = 0; i < document.links.length; i++)
{
l += document.links[i].href + ‘\r’;
}
l” in document 1 of window 1
paragraphs of result
return result
this will only return “” instead of a list of links.
I tried the above code and can’t gt that to work for me.
Does anyone know what has been changed in the syntax?
-ChuckD
Browser: Safari 312
Operating System: Mac OS X (10.3.9)
This works for me (again, in Safari 2.0/Mac OS X 10.4 but Safari 2.0 & 1.3 should operate in exactly the same way):
tell application "Safari" to set allLinks to ¬
(do JavaScript "
l = '';
for (i = 0; i < document.links.length; i++) {
l += document.links[i].href + '\\r';
}
return l;" in document 1 of window 1)'s paragraphs 1 thru -2
Jon
Model: PowerBook 1.25MHz
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)
But what happened?
Is there any documentation as to what exaclty is changed in the syntax support?
I use quite a few do Javascript commands. All are different and I can’t go back and re-write everything.
I’ll check you code above tonight and see if it works for me.
-ChuckD
Browser: Safari 312
Operating System: Mac OS X (10.3.9)
tell application "Safari" to set allLinks to ¬
(do JavaScript "
l = '';
for (i = 0; i < document.links.length; i++) {
l += document.links[i].href + '\\r';
}
return l;" in document 1 of window 1)'s paragraphs 1 thru -2
In the above code I sometimes get a crash where the Safari doesn’t return anything in paragraphs 1 thru -2…
How do I put a condition around this above code to only try to return the value if it exists?