Help with Safari Java...

Hi all…
I’m trying to write a script that will automatically get directions from the cool new site. But I don’t know how to script the Java form. This is what I’ve come up with:

tell application “Safari”
open location “
delay 2
do JavaScript (“Run Script javascript:directionsSearch(‘9531%20Robin%20Ave,%20Westminster,%20CA,%2092683’,%20’123%20Main%20St,%20Jacksonville,%20FL%2032233’,%20true”) in the front document
end tell

Maybe I’m not understanding the “do JavaScript” command, 'cause it sure isn’t working. Anybody able to help?
Thanks in advance…

You could use JavaScript, but you don’t need to:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

This works wonderfully, and will certainly fit into my script. Thank you!
As for understanding how you did this, I guess I’m going to have to hit the books for a few months in order to understand HOW it works. Any chance you could insert some (* comments *) for assistance?
Also, with your permission, I’d like to credit you in the next version of my “MakeMapFromTwoAddresses” freeware script for Apple’s Address Book. Could I get your last name?
Thanks again!

  • Ron

My last name is Nathan. This script was pulled from an Address Book plugin I had written:

As to commenting this, I think the only things that aren’t particularly straightforward are the list_to_string and encode_URL_string handlers. The list_to_string handler simply uses text item delimiters to concatenate a list to a single string using whatever delimiter you’d like. Usually, when combining a string, AppleScript uses the default delimiter “” but you can use anything like a hard return to create a list of paragraphs or, in this case, a comma.

The encoding handler is a bit more complex and I’m not going to go into Hexadecimal encoding suffice it to say, the handler breaks a string into individual characters, looks at each character and sees if it needs to be encoded as a HEX entity so it can be passed as a valid URL character (e.g., a space (" ") needs to be “%20”). If it does need to be encoded, the item in the character list is replaced with the encoded entity and then the entire list is reconfigured as a string and returned.

Hope that helps.


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thanks for the clarifications! You’ve really helped my understanding of AppleScript up to a new level!
For some reason, I was not able to get the second script to do anything at all.
Anyway, I’ve made a version 2.0 of MakeMapFromTwoAddresses, giving you a lot of credit. You candownload it at:
Thanks again!

You should save the second script I posted above in the ~/Library/Address Book Plug-Ins/ folder. Name it something like “Directions to this Address.scpt” Now, when you launch Address Book and click on the address label of a contact, a drop down menu will show “Get Google Directions to from Home”. Select this and the Google maps page should load with directions from your home address. There could be more error checking to make sure the info for the address is actually there but, I hadn’t gotten around to that yet.