Hello all,
I have been having difficulty with this issue. I wish to set a text field to a string defined within a plist on the start of the application. What I have now is at the start of the program, the plist is called and the string that I want set is defined as a property in the beginning, then when I do a set property to contents of text field textboxname, the text box is still the default. Any suggestions? Thank you.
Are you setting the the value of the property value to the value of the text field or are you
wanting to set the value of the text field to the current value of the property?
Post some code and a little more detail on the results you are expecting.
Cheers,
Craig
Here are the sub-routines and the main outline I always use to save values in the plist file. Hope this helps:
property VariablePref : "Initial Default Value"
on launched theObject
readPrefs()
end launched
on readPrefs()
if not (exists default entry "My_Pref_1" of user defaults) then
make new default entry at end of default entries of user defaults with properties {name:"My_Pref_1", contents:VariablePref}
else
set VariablePref to contents of default entry "My_Pref_1" of user defaults
end if
--maybe here you would put: tell window whatever to set contents of text field whatever to VariablePref
end readPrefs
--Not sure how you are triggering the write of the new value to the plist file
set contents of default entry "My_Pref_1" of user defaults to VariablePref
I would add it right after readPrefs() in the on launched handler.
Read the prefs and then set the text field.
Have you tried setting the text field and had trouble making
that work?
I’m sorry for the lack of information, I have been busy lately, but this is what my original intention was:
property variableOne : ""
-- Calling the variable from a plist
set theOutputFolder to path to desktop folder as string
set thePListPath to POSIX path of (theOutputFolder & "application.plist")
set theOutputFolder to path to desktop folder as string
set thePListPath to POSIX path of (theOutputFolder & "application.plist")
tell application "System Events"
tell property list file thePListPath
tell contents
set value of property list item "somevariable" to variableOne
end tell
end tell
end tell
-- This is where I want the property "variableOne" to show up already set on launch of the program
set contents of text field "textField" of window "Window" to variableOne as text
on clicked theObject
-- The rest of the code
end clicked
The problem is that the called property is set correctly, but the start of the program doesn’t show the text field as the property called, even though it was properly called. I haven’t looked into Matt-Boy’s setPrefs yet, but this was what I was working with.
Your program does not know to load the information if you do not tell it to in an on launched or awake from nib handler like Matt-Boy demonstrated. You are also going about it the hard way to setup a plist file. User defautls is the way to go. There is a tutorial in unScripted that covers how to do that in great detail.
http://bbs.macscripter.net/viewtopic.php?id=24666
Cheers,
Craig