Applescript form in Xcode to Mail

I am fairly new with Xcode and Interface builder. I am running into a bit of trouble while trying to make a simple app that will create an email with several properties. All I want it to do is to take the email entered in the form and put it in the “TO:” field. Everything else in my code seems to work fine, it’s just getting what is entered in the text field to transfer over. I created a subclass of NSObject called AppController and I believe I properly linked everything as outlets and actions go. I have been trying to solve this on my own for hours, any help is greatly appreciated!

For reference, this is what the app looks like:

http://img683.imageshack.us/img683/7485/screenshot20101005at125.png

script AppController 

property parent : class "NSObject"

 property textForm : missing value

 on sendInfo_(sender)

  tell application "Mail"
   set newMessage to make new outgoing message with properties {visible:true, subject:"subject goes here", content:"hello world"}
   tell newMessage
    make new to recipient with properties {address:textForm}
   end tell
  end tell

 end sendInfo_
end script

Try:

make new to recipient with properties {address:(my textForm's stringValue()) as text}

But you should probably move the textForm stuff outside Mail. So before you Mail tell block, use:

set theAddress to (textForm's stringValue()) as text

And then just use the variable.

This is my new code, but still for some reason it’s not populating the “TO” field. Would it be safe to say that there is something else wrong with my project?

script AppController
	
	property parent : class "NSObject"
	
	property textForm : missing value
	
	on sendInfo_(sender)
		
		set theAddress to (textForm's stringValue()) as text
		
		tell application "Mail"
			set newMessage to make new outgoing message with properties {visible:true, subject:"subject goes here", content:"hello world"}
			make new to recipient with properties {address:(my textForm's stringValue()) as text}
		end tell
		
	end sendInfo_
	
end script

Have you connected textForm to the text field in Interface Builder? What appears in Console if you add the line:

log

theAddress

?

I’ve connected the textForm to the text field in Interface Builder. Where in my script did you want me to add “theAddress” ? In Console I get this message:

So it looks like you have a Mail scripting problem, and that’s probably better sorted out outside Xcode. I don’t use Mail, but I suspect address wants something other than a simple string, probably a record.

You have to tell newMessage to make the new recipient not Mail. Try this:

script EmailsAppDelegate
	property parent : class "NSObject"
	property textForm : missing value
	
	on sendInfo_(sender)
		set theAddress to (textForm's stringValue()) as text
		tell application "Mail"
			set newMessage to make new outgoing message with properties {visible:true, subject:"subject goes here", content:"hello world"}
			tell newMessage to make new to recipient with properties {address:theAddress}
		end tell
	end sendInfo_
end script