Saving

I made an Applescript application (not a document based one) that calculates some numbers entered into the main window and puts the total in a text field on the attached drawer. For example, at the top of the window is a text field that displays the current date. Numbers are enterend into the other text fields (on the main window) and a total is calculated. The app. then looks at the date and if Monday is in the date, it puts the total into textfield “day1” which is located in the drawer. I want to store the totals put into the drawer so that as each new day is filled a running total is put into a textfield at the bottom of the drawer. Hope this isn’t too confusing. the second problem is that I have connected the save menu item to the first responder and selected “savedocument” yet the save menu item is still grayed out when I build the app. I even tried making a document version just to see if that was the problem. No luck though.
Thanks in advance.

First, I wouldn’t go fooling around with ‘connecting’ things. 99% of the time, it’s not necessary when writing your app in AppleScript via AStudio.

To store something in AStudio’s built-in preference system ‘aka user defaults’, here’s what you need to know.

First, you’ll need to establish each preference you wish to store something IN like so:

make new default entry at end of default entries of user defaults with properties {name:"mypreference1", contents:someValue}

Insert the above in a startup handler like ‘on awake from nib’ or ‘on launch’. I usually put them in ‘on launch’.

Next, to alter said preference, the command is worded like so. This is typically used when you want to set the preference value to something new:

set contents of default entry "mypreference1" of user defaults to "somenewpref"

Next to determine the current value of said preference, go this route. This would be used, say, when you need to get the value of the preference in order to reflect that preference to the user’s setting. Like whether or not to show a specific window or alter its size according to the preference they set before:

set someValue to (contents of default entry "mypreference1" of user defaults)

Finally, in regards to your ‘save’ problem, I thought you said you didn’t have a document-based application. If you’re just trying to save a preference, follow the instructions above and simply turn on the ‘on choose menu item’ event for that save command menu item. Then, insert a preference-saving line like:

set contents of default entry "mypreference1" of user defaults to "somenewpref"

Note: default entries can contain varous data types like boolean (true/false), strings (“mypetrabbit”) and lists like {“one”, “two”, “three”}

Finally, you should know that once default entries are ‘initialized’ and is present in your app’s plist file (user/library/preferences/), say, on first launch, the declaration command (make new default entry…) is ignored. This keeps the preference from getting reset back to whatever its value was upon initialization, therefore NOT overriding whatever you or the user might have set it to within your running code.

Thanks for the reply. I was beginning to think noone could help me. I read your post and I’m a little confused, but I’m sure once I get back to Project Builder, I can work through it. I have to be at our gig in an hour so I’ll give it a try tomorrow. Once again I really appreciate it.
As for saving, all I’m trying to do is be able to click the “save” choice in the applications menu and have it remember what was in the text fields when I open the app. up again. It’s a simple calculator type app.
Once again, thanks.

Give it a whirl. If you don’t get it going with the first few attempts, post your entire script code (handlers and all) and I’ll walk you through it.

THAT would be extremely cool of you. I’ll give it a try. I’ll definitely have to find a way to send you a CD when it’s done.
Thanks again!