Is there any ONE article or post on the web I can look at for a list of every “do javascript” command?
do you know the first google search result (keyword: “do javascript” applescript)?
I’ve already seen that one, it only has a handful of commands. Any others?
This one is good.
http://www.devguru.com/technologies/ecmascript/QuickRef/javascript_index.html
Peter B.
It is a little bit late, you definitely found your javaScript reference, but for later viewers of this thread the links below are on my opinion quite handy whenever you need to refresh your memory as how to access some elements in the DOM:
http://www.w3schools.com/htmldom/dom_nodes_access.asp
http://developer.mozilla.org/en/docs/The_DOM_and_JavaScript
The one below is unfortunately in German. It is excellent. It is so clear and full of examples that it is worth giving it a chance even if one do not speak German. On my opinion it is by far the best available.
http://de.selfhtml.org/javascript/objekte/index.htm
One so often forget that AppleScript is not the only OSA language: JavaScript can also control your mac. The people at Latenight found ways to put up a beautiful reference of the MacOs X dom object.
http://www.latenightsw.com/freeware/JavaScriptOSA/MacOS.AEClass.html
I wish the communications between AS and JS would be more direct.
That would make a quite powerful solution indeed.
Orso
This seems like it would be something useful to me however I am uncertain or how you would use applescript and javascript a simple exmple of how this works and why one might possibly use this for would be greatly appreciated
thanks
mcgrailm
Ciao mcgrailm,
using the (very handy) “do JavaScript” command in Safari you’re able to access almost every property of a given webpage and use it for your script.
For example this will download every image of a given webpage to the user’s picture folder:
with timeout of 600 seconds
set otid to text item delimiters
set text item delimiters to "/"
tell application "Safari"
set imageCount to (do JavaScript "document.images.length" in document 1)
repeat with i from 0 to imageCount
try
set imageURL to (do JavaScript "document.images[" & i & "].src" in document 1)
set imageName to last text item of imageURL
set savePath to ("~/Pictures/" & imageName)
set curlCommand to ("curl " & imageURL & " -o " & savePath)
do shell script curlCommand
end try
end repeat
end tell
set text item delimiters to otid
end timeout
Good scripting
Farid
mcgrailm, if you were a user of adobe’s applications you could use AppleScript to handle everything out side of the app then once in a tell document block do JavaScript to handle everything inside. Adobe have put much more into what you can do with JavaScript over AppleScript. Acrobat has had nothing added since V6 and they are not looking at it either. Which is nice as my whole work flow is now pdf.