Saturday, January 2, 2010

AppleScript and JavaScript

1. You can actually insert JavaScript commands inside AppleScript. The syntax is "do JavaScript", as in:
tell application "Safari" to do JavaScript "alert('Hello, world!')" in document 1
or
do JavaScript "window.print()" in document 1

2. You can write blocks of JavaScript code and then save the code as a bookmark, and then call the bookmark from a browser, and the JavaScript code will run. There is a lot on the web on this trick, which even has a name: Bookmarklet. There are all kinds of Bookmarklets out there for public consumption, like widgets. You can have an onscreen calculator, you can change the color scheme of a web page, you can fill out a web page, etc. etc.

3. You can pass variables from an AppleScript to a web server by inserting the variables into an HTML GET, as in:
set the URL of document 1 to "http://localhost:8888/foo.php?key1=" & val1 & "&key2=" & val2

4. You can use your iPhone as a dictaphone by using the free Dragan App (trick: "send to clipboard")
You can automatically send the clipboard contents to MobileMe email (trick: use free ClipMail app)
MobileMe email is push email, and can be used to launch an AppleScript on a MacBook Pro (trick: use Apple Mail Rules)
AppleScript can retrieve the contents of the email, parse it, and send it to a web server by calling a php script which inserts the contents into an SQL database.
Thus, following these steps, you can DICTATE into your phone and the text is instantly available in a REMOTE SQL SERVER, already parsed, with individual words and phrases sorted and inserted into records.

5. You can debug AppleScripts by having the script SPEAK the variable values or DISPLAY the variable values in dialog boxes:
display dialog var1
set speakString to "The value of var1 is" & var1
say speakString