Text-to-String

when I try to turn a text box into a string it just says "can’t make <> into type string. The name of the text box is text. How do I declare it to be a string/variable so I can transfer it to “Mail” app? Thanks!:D:D:D

A text box into a string? That’s odd. wait, do you mean the contents of a text field?

 set myVariable to contents of text field "whatever" of window "whatever" 

yeah, the contents of one.

Model: iMac Core Duo
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

I entered it in but It will not transfer the text:

property textnote : ""
on choose menu item theObject
	tell window of theObject
		try
			set textnote to contents of text field "text" of window "Note"
		end try
	end tell
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:"Sent via Notee!", content:textnote & return & return}
		tell newMessage
			set visible to true
		end tell
	end tell
end choose menu item

Model: iMac Core Duo
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

Your reference to the text field is incorrect. You’re effectively saying.

contents of text field "text" of window "Note" of (window of theObject)

.that is, you’re code is looking for window “Note” inside another window; there is no such thing in your application, so an error is raised. However, your try block catches said error and does nothing with it, so the value of ˜textnote’ is not changed.

In the above piece of script, I think you should remove the tell and try block.

I did what you suggested:

property textnote : ""
on choose menu item theObject
	set textnote to contents of text field "text" of window "Note"
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:"Sent via Notee!", content:textnote & return & return}
		tell newMessage
			set visible to true
		end tell
	end tell
end choose menu item

But this error comes up:

I can’t understand why it will not work! I have been struggling with this app for a while. Your help is greatly appreciated.

your script seems to be ok - so probably the mistake is still in

set textnote to contents of text field "text" of window "Note"

Maybe the text field is part of a box? You can easily find out: when selecting the text field in Interface Builder you’ll notice that the box will be highlited along with it. If so you would write something like:

set textnote to contents of text field "text" of box "thebox" of window "Note"

D.

It is just a window with a text field in it. This puzzles me greatly… I have named the text box (in interface builder) “text”. It has no attachments to any script, though…

Model: iMac Core Duo
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)

Hi,

I think I’ve seen this behavior and what I did was change contents to content.

gl,

Hi,

This is puzzling.

I use both “content” and “contents” interchangeably in my application without any problem…though I do use “contents” most of the time.

Could you try changing the property name “content” to “contents” in the bracketed code below and see if it’ll make any difference?

tell application "Mail"
       set newMessage to make new outgoing message with properties {subject:"Sent via Notee!", content:textnote & return & return}

Another possible source of error (though I am not sure of this) is the use of the property name “content” in the bracketed code. Could this be a reserved word? Try changing that into some other property name and see what happens.

Both are educated guesses that might be worth trying.

Good luck!

archseed :slight_smile:

Hmm. sending stuff via Mail. I’d bet the pennies on my desk that Jack is actually using a text view.

set textnote to contents of text view "text"  of scroll view "whatever" of window "Note"

According to Mail’s dictionary, content is a property of a message. (Also, those are braces, not brackets. :))

Wow! thanks you guys, I think Bruce is right. I’ll try it out when I have the time (I’m kinda busy now) and I’ll tell you if it works!:D:D:D
Sadly it still says “NSreciever error…”. I don’t know how to name a scrollview, could anyone point that out. As for Mail, It can actually transfer the contents of textnote if I, Say, wrote

property textnote : "hello world"

the hello world text would go through. It is just getting the text from the text view that is the trouble.

Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)