I have a text field called “RefreshRate” and the value for that field is stored in a file outside of the app. The problem is that whenever the app is restarted, the value in RefreshRate goes back to the default I set in mainmenu.nib even though its actually the value stored in the file. Basically, how can I use applescript to set the number in that field?
for example:
tell "MainMenu.nib"
set value of text field "RefreshRate" to value from file Example.txt
end tell
Ok, here is a quick description of using user defaults
define a property
property RefreshRate : "1"
create these handlers
on register_Preferences()
tell user defaults
make new default entry at end of default entries with properties {name:"RefreshRate", contents:"1"}
register
end tell
end register_Preferences
on read_Preferences()
tell user defaults
set RefreshRate to contents of default entry "RefreshRate"
end tell
end read_Preferences
on save_Preferences()
tell user defaults
set contents of default entry "RefreshRate" to RefreshRate
end tell
call method "synchronize" of object user defaults
end save_Preferences
in your handler to initalize values (e.g. awake form nib) insert these lines
on awake from nib theObject
-- .
register_Preferences()
read_Preferences()
tell window "main" -- or whatever its name is
set contents of text field "RefreshRate" to RefreshRate
end tell
-- .
end awake from nib
I did what you said, but when I change the value, exit the app, and then restart the app, the value is still not changing. I don’t just rebuild, I release it everytime and it still doesn’t work. Any suggestions?
Hmm - the value is saved on ‘end editing’ - means it needs at least a return or a tab or a change of focus by clicking in an other focussable element to store the value in defaults. Maybe you had just entered sth and quitted your app instantly afterwards?