Getting value of a text box and saving it

In my AppleScript XCode project I have a text field named RefreshRate in my preferences area. I was wondering how I could get the value of that text feild so I can use it in other parts of my main AppleScript for the project.
I have tried:

set x to value of text field "RefreshRate" of "Mainmenu.nib"

but I get a weird error.
If it is of any help, the name of the window the text field is in is simply “Preferences”

Second, I know how to set the default of that text field in Mainmenu.nib, but how can I save the changes the user makes so everytime they open the app it is the value they last entered?


then try simply

set x to value of text field "RefreshRate" of window "Preferences"

Note: the text of any error message, you’re asking about, could be very helpful :wink:

set it during one of the first handlers the application runs like awake from nib or will finish launching and use user defaults to save and restore user data.
You can find a tutorial here

With your suggestions for the part of getting the value I get the error “Can’t make value of <> “RefreshRate” of window “Preferences” into type reference. (-1700)”

Thanks for your help in this post and my other ones.

then try this

set x to contents of text field "RefreshRate" of window "Preferences"

Thanks much, that works. Now I just need to figure out how to save it when the user changes it. I have the text box in a Preferences window. Its default for when the app opens is 4, but the user can change it. I’m not sure how to get it to change the default to whatever the users picks, and that link was kinda confusing to me. Do you have any other suggestions?

the crucial paragraph in the mentioned article is Gentlemen Prefer Preferences.
The description how to use user defaults is quite clear

I figured out a different way of doing it, but that has brought a new question. How do I get the text of a certain file? For example if the file Example.txt contains the character “6”, how could I get that character into an Applescript variable?

Something like:

set y to contents of file "Example.txt"

Would that work?

I used:

	set y to text of file "Example.txt"

and got: "Cant make every text of file “Example.txt” into type reference.

and set y to contents of didnt work either.

using text files for saving preferences is possible, but the user defaults is the much better solution.
You can read or write text files only with the read/write commands, your examples can’t work.

What is the problem to use user defaults???