SOLVED!
I guess I just needed to tell system events to tell the process safari to do my bidding. New code:
set listURL to {}
set listName to {}
tell application "Address Book"
--set thePeople to selection
--set thePeople to properties of name of people
repeat with aPerson in people in group "Facebook" -- thePeople
set currentURL to value of url of aPerson
set currentName to the name of aPerson
set end of listURL to currentURL
set end of listName to currentName
end repeat
end tell
repeat with fb in listName
set thePerson to fb as text
set theSubject to "Automated Contact Info Request"
set theMessage to "Hey " & fb & "! I am updating my address book and I don't seem to have your contact info. If you could please get back to me with your Address, Phone -or- Cell, Email, and any relevant IM information it would be greatly appreciated! ~Aaron"
tell application "System Events"
tell application process "Safari"
open location "http://www.facebook.com/ajax/messaging/composer.php"
delay 8
--activate
keystroke thePerson
keystroke tab
keystroke theSubject
keystroke tab
keystroke theMessage
--keystroke tab
--keystroke return
end tell
end tell
set answer to the button returned of (display dialog "Continue?" buttons {"Yes", "No"} default button 1)
if the answer is "yes" then
--
else
return
end if
end repeat
Old post starts below
I am writing an automation script that goes though my Address Book contacts, finds the ones with a facebook URL, and then sends them a canned message asking for their updated info. My original idea was to use the URL in Address Book and gui script clicking send message to but I realized that I could just goto the url http://www.facebook.com/ajax/messaging/composer.php and it would open a new message and it would default to the first text box and wait for text. When I try to keystroke the information in I get and error stating that applescript cannot keystroke the persons name.
set listURL to {}
set listName to {}
tell application "Address Book"
repeat with aPerson in people in group "Facebook"
set currentURL to value of url of aPerson
set currentName to the name of aPerson
set end of listURL to currentURL
set end of listName to currentName
end repeat
end tell
repeat with fb in listName
set thePerson to fb as text
set theSubject to "Automated Contact Info Request"
set theMessage to "Hey " & fb & "!
I am updating my address book and I don't see to have your contact info. If you could please get back to me with your Address, Phone -or- Cell, Email, and any relevant IM information it would be greatly appreciated!
Thanks,
Aaron"
tell application "Safari"
open location "http://www.facebook.com/ajax/messaging/composer.php"
delay 8
activate
keystroke thePerson
keystroke tab
keystroke theSubject
keystroke tab
keystroke theMessage
keystroke tab
keystroke return
close document
end tell
set answer to the button returned of (display dialog "Continue?" buttons {"Yes", "No"} default button 1)
if the answer is "yes" then
--
else
return
end if
end repeat