Saving strings in user prefs file

Hi all,
I'm experimenting with user preferences. The IB interface works okay, and the panel appears when selected from the 'Preferences...' menu item. I do have one slight issue with it, but I'll deal with that as a separate question later.
In the meantime, I just want to store (1) a name string and (2) an address string , but all the example code I've been able to find has dealt with storing data objects only. Now if I've got this right NSStrings don't need to be stored as objects, so how do I modify my code to achieve this?
Here's my 'PrefsController' header file:
// PrefsController.h
#import <Cocoa/Cocoa.h>
extern NSString *nameKey;
extern NSString *addressKey;
@interface PrefsController : NSWindowController
IBOutlet NSTextField *nameField;
IBOutlet NSTextField *addressField;
<snip>
@end
...my 'PrefsController' main file:
// PrefsController.m
#import "PrefsController.h"
NSString *nameKey = @"name";
NSString *addressKey = @"address";
@implementation PrefsController
-(id)init
self = [super initWithWindowNibName:@"Preferences"];
return self;
<snip>
@end
...and finally, my 'AppController' main file, where the problem lies:
// AppController.m
#import "AppController.h"
#import "PrefsController.h"
@implementation AppController
+ (void) initialize
// Create a (mutable?) dictionary
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
//••• usual place for NSData object below •••
//••• place for unknown default values below •••
[first default value];
[second default value];
// Register the default dictionary
[[NSUserDefaults standardUserDefaults] registerDefaults: defaultValues];
NSLog(@"registered defaults: %@", defaultValues);
<snip>
@end
As you can see, the problem is in AppController.m, with (1) the omission of an NSData object, and (2) the unknown default values required.
Since this test app will never be asked to do more than swap two strings, another thing I'm curious to learn is if I could use a plain NSDictionary instead of a mutable one?
Any help would be much appreciated. Thanks!
Ernie

Hehehe..... Thanks again, phunkjoker. The bindings fixed this issue in seconds! The prefs function is now creating a file in Library/Preferences/ and saving and retrieving strings. Dammit, I love this Cocoa.
While all the demo code I've managed to find makes no mention of Shared User Defaults, I can see how useful (even critical) this is, but realise such 'refinements' probably won't find their way into bare-bones examples.
Unfortunately, because I've been on such a roll with the practical stuff I've far outpaced my understanding of Cocoa theory, and will spend the next few days going through the docs -- in particular, the ones you listed. In one way, getting ahead of myself is good because the material is going to make a lot more sense as I read it. Also understood what you said about the '+' initializer.
In the meantime, I actually do have two much smaller issues remaining...
(1) The prefs panel has two NSTextFields labelled 'email' and 'login' respectively (required for ID as part of a header in my text file output, rather than indicating any grandiose plans on my part to mess in these areas). I noticed that in order for any changes to be saved, I must subsequently click or tab *out of the box* again (into the remaining field) before quitting out.
(2) The example app I followed has no 'Okay' button, and therefore no means of disposing of the prefs panel other than quitting. Now, after much searching, the most likely candidate I found was orderOut:. Putting this in my 'prefsController.m' file as an 'Okay' button action, I have:
-(IBAction)okayPrefs:(id)sender
NSBeep(); // my code required here
[window orderOut:self]; //••• experimental
As it stands, the build fails due to 'error: 'window' undeclared (first use in this function)'. Declaring 'window' in 'prefsController.h' like this:
@interface PrefsController : NSWindowController
IBOutlet NSTextField *emailField;
IBOutlet NSTextField *loginField;
IBOutlet NSPanel *window; //••• experimental
-(IBAction)okayPrefs:(id)sender;
-(IBAction)cancelPrefs:(id)sender;
@end
...allows it to build successfully, but has no effect when I click the button. Any guidance on these items please, or should I float them in a separate post?
Ernie

Similar Messages

  • Where is my user pref file?

    The icon in my Users & Groups preferences keeps changing back to one I don't want, no matter how many times I change it. I think the preferences file is corrupted and would like to delete it, but where is it in Lion? There used to be a Library folder in the user folder. Help!

    I think I have solved my issue. When I looked at the pref files I found a number of gibberish files, usually in groups of two or three, which appeared to have no content. I deleted these and so far so good!
    The files deleted were:

  • What are the results of trashing multi-user prefs?

    Hello to all,
    I've forgotten my password to my Owner account, and I'm aware that to reset it I have to trash Multi-User prefs whilst booted from a CD. I know that doing this will delete all my accounts and passwords, but will it also delete all the files in these accounts? Also, will it delete all the files in the Owner account?
    Original iBook G3 Clamshell   Mac OS 9.2.x   288MB RAM, 20GB HD, 300MHz

    Hi, bananaboy -
    Since it is a file and not a folder, the Multi-User Prefs file can not contain the files in the individual accounts - if it did, it would be larger than all the other info on the drive combined.
    When you trash the file Multi-User Prefs, no other files get trashed - they can not. All that disappears are the passwords and other account settings that are stored in the Multi-User Prefs file.

  • Forgot password and cannot find file named "Multi-User Prefs" to trash

    hi- i have a Power Mac G4 with Mac OS 9.0.4. I forgot my password. I tried to boot the iMac with PowerMac G4 Software Restore CD.
    In System Folder (on the hard drive), I could locate Preferences folder but i could not find the file named "Multi-User Prefs"
    Please suggest what I can do to reset my password.

    "I tried to boot the iMac with PowerMac G4 Software Restore CD."
    You need to boot from the System "Install" CD(hold down c key after you restart).
    Go to the hard drive click on System Folder then click preferences then trash Multiple Users Preference!

  • Submitting a user's file to an applet.

    Hi,
    I am fairly new to Java, but I have spent a large part of this year learning about and using Java to write a program for biochemists, to allow them to study a particular class of enzymes. I have used Java because I wanted to enable to program to be used by people via the internet, and I wanted there to be a good graphical interface. Java Applets have enabled me to do this. Furthermore, some of the computation has to be done via the server, because the Applet interfaces to a Prolog program, and again this was easy with Java, because I was able to do this using (HTTP interface) Servlets.
    There is one major drawback to this solution. The users will often develop 'models' of their enzyme, which they will want to save to a file, and reload at a later stage. However, Applets cannot access the user's file system, which means I had to find another way to achieve this. At the moment, loading (and saving) the models is done in a two-step process. A form, embedded in the web page below the Applet, is used to submit the file to a Servlet, which saves the contents of the file to a session object. Then, the user clicks on a button in the Applet, which connects to another Servlet, and the file is read from the session object, and transmitted back to the Applet. Saving a file is just the reverse of this process.
    Quite apart from the fact that it is a nuisance to do this transaction in two steps, it causes problems when the user doesn't have cookies turned on. I can always alert people to the fact that they need to turn cookies on (or use URL encoding), but it still means that there are two steps to the process.
    Does anyone have any suggestions how I might be able to write this sequence so that the user can load or save a file in only one step, instead of two? Someone suggested that I use sockets, but from the reading that I have done, it seems that Servlets are simply a convenient way to use sockets. So, it seems using sockets would just be a more difficult and time-consuming way to achieve the same end.
    Any suggestions on this topic would be gratefully appreciated.
    Regards,
    Sarah

    Thanks so much for your prompt reply.
    Every time the user performs an action in the applet that connects to one of the servlets, I extend the lifetime of their session object. That way, when they submit a file to the server, it is available for them to access it for a couple of hours, before the session object will time out (unless the user accesses the server in the meantime, which resets the lifetime of the session to 2hrs).
    The problem isn't actually passing the file from the servlet to the applet (or vice versa) - I already use IO streams to do this. The problem is can I get the file from the HTML form to the applet in one step?
    As far as I can see, if the connection to the servlet comes from the html form, then the response goes back to the browser. Similarly, if the request comes from the applet, the response goes back to the applet. What I am wondering is, is there a way to force communication from a servlet to the applet when the initial connection to the servlet has come from the browser (i.e. from the HTML form)?

  • I was told to delete user.js file to stop viewing the "tour" page on start, file does not exist, problem remains

    i updated, i start firefox 2 tabs open one is "take the tour" tab the other is google, done the tour, a few times it opens up again every time, start of the healing process by typing in the question '"i keep seeing thr "take the tour"page on startup,then following the steps of the expertise i go to help,trouble blabla and i end up looking for user.js so i delete it or rename in a folder that contains folders and other data that nothing in there is like user.js file, so in the following question that is formed above there was no answer so i stepped into this case (only i had to create an account that was not my desire in the process) , thats all i know of.

    So, if you do not have the user.js file then you can rename or delete the prefs.js file (pref.js.sav) to see if that helps.<br />
    Windows likely hides the .js and shows them as User and Prefs.
    You can also try to delete the compatibility.ini file to force Firefox to reinitialize some other files.
    You can use this button to go to the currently used Firefox profile folder:
    *Help > Troubleshooting Information > Profile Directory: Show Folder (Linux: Open Directory; Mac: Show in Finder)
    *http://kb.mozillazine.org/Profile_folder_-_Firefox

  • Powerpoint 2013 throwing 'File in Use' errors when saving to a network drive, file is NOT in use

    One of our sites is having a strange issue when saving to a network location in Powerpoint.  I'm not sure it's a Powerpoint problem, but it's a place to start...
    When saving a ppt to a mapped network drive (the client is running Windows 8 / Office 2013, the network drive is a DFS share, pointed to a Server 2012 machine if that matters), users will almost always get the following error:
    "Someone else is working in (filepath\name) right now. Please try again later." 
    This happens regardless of where the file is being saved on the network drive, in fact it happens even when there is no pre-existing file with that name in the location.  So, even if I'm saving a brand new copy of test.pptx to F:\Share\PPT where there
    is not currently a test.pptx, I get the error.
    Word, Excel, and all other tested apps save properly.  Powerpoint can save correctly to the local computer, but not to the network drive or to My Documents (which redirects to the same network drive).
    When the error pops up, if I look in Open Files in Computer Management on the Fileserver, I see the file I'm trying to save listed as being open, but it shows 'Disconnected' rather than a username.
    Any suggestions would be appreciated - again, not sure that this is a Powerpoint problem - could be Windows 8 or some mysterious DFS thing...
    Thanks.

    Hello,
    Been having a very similar issue in our environment and just came across this thread while Googling and looking for answers.
    In our case, we have Windows 7 clients and 3 main files servers - 2 are Server 2008 R2, and one is Server 2012.  We use PeerLink File Collaboration to sync the files between
    the servers (similar concept to DFS).  For us, it seems to happen specifically with Excel 2013, and only when saving to the Server 2012 file server.  I can reproduce the message pretty much every time.  After seeing your post,
    I tried it in Powerpoint just out of curiosity, but it saved properly - Word saves properly as well.  
    Been doing a bunch of testing to try and narrow it down, and this is what I've found:  
    Excel 2013 -> Server 2012 = error message.  
    Excel 2013 -> Server 2008 R2 = no error message.  
    Excel 2010 -> Server 2008 AND Server 2012 = no error message.
    <o:p>We've been leaning towards the PeerLink replication as the culprit up to this point, but last night I did some testing with the PeerLink Collaboration turned off, and
    still received the error message.. so now I'm even more confused! 
    I see that it's been a few months since your post..  have you made any progress here?</o:p>

  • Allow a simple form with "data" to be saved by the user.

    Back in version -x, it used to be so simple.  You created a form that could be read in a web browser.  Users could could fill out the form and save the form to their computers with their data.  Since that first version that allowed that, Acrobat has not progressed in logical fashion.  In a later version, you couldn't save the data.  Then in another version, you could again save the data.  Now you have some nice interactive features. I appreciate the new developments and see where they could be a godsend.  However, the simple thing that I used to be able to do in version -x, and the thing I most want to do,  I can no longer do and it is frustrating.
    Here's the situation:  we have an announcement on the web for Vacation Bible School.  We want to have a pdf with a form that people can fill out online and save to their disk (as their copy of the registration form) and then print out one copy of the form so that they can send it along with their check for the registration fee.  Why should that be so difficult?
    If it weren't for the fact that people have to send in checks, one of the fancy new options would work.  But it is not applicable in this situation.
    Here are my current options:
    I can "distribute" an emailable form (which I don't want to do) and then explain to the user that they should not hit the "submit" button but save the file to their disk.  (First rule of public relations - Don't confuse the public!)  It works in the last version of REader 8+ and in Reader 9.
    I can save the form without distributing it. But the user can't save it with the data!
    Please, PLEASE, PLEASE.  Allow a simple form with "data" to be saved by the user.
    Peace and blessings
    Barbara

    Thanks for a quick response.
    In Acrobat *8 or 9 Professional you can enable a form to be activated with the save feature.
    How do you do this.  When I saved the form without distributing it, and opened the form up in Acrobat Reader, the header said specifically that the data could not be saved in the form.  And when I went to save it, I got the message in a popup that said "Data in this form will not be saved. Reader can only save a blank copy of this form."  Then a second message (with a light bulb) said:  "Please print your completed form if you would like a copy for your records."
    So, if in fact I can have the form (without "distributing" it) so that the user can save the form with the data, how do I do that?  Are there commands I use, options?  Please let me know.  I will be eternally grateful.
    Also, if you edit form fields, you may remove the submit button.
    The edit form fields does not offer any access to the submit button.
    Best,
    Barbara

  • Garageband custom "user-loops" files missing

    I'm using Garageband '09 (Version 5.1 (398) and I am having trouble locating my custom "user loops" files.
    I know that custom made apple loops are saved in
    Library/Audio/Apple Loops/User Loops
    I have about 100 loops saved in the folder, but in Garageband I have over 200 saved custom made loops that work fine. I am able to use all of the loops, only about half of them have files in the correct place.
    Doing a spotlight search does not find anything, even when I search for the custom loop name exactly and search "This Mac" and "Library".
    One strange thing I've found is when viewing the loops browser, at the top there is a dropdown labeled "Loops" that offers the filters "My Loops" and "Shared Loops on my Mac". It seems that I can only find the files for "My Loops" and the "Shared Loops on my Mac" are the missing ones.
    Is there another place these files could be saved? I can use them in Garageband so they must be somewhere.

    How can I create loops that are "My Loops" vs "Shared Loops on my Mac" on purpose.
    Check your Preferences setting:
    In the "Loops" tab of the Preferences panel - the "My Apple Loops" option.
    If you share your loops with all users on your mac (users havg different accounts) then the loops will be installed in the System Library, but if you do not share, your loops will be installed in your user library. If you log in from a different account you will not be able to use them.
    Regards
    Léonie
    I don't have Logic installed, but both installation places should make it possible for Logic and MainStage to use the loops. It is the standard place where applications are looking for Apple Loops.

  • Share microsoft office documents not saving on all users

    Set up new user account for my wife
    shared my "desktop" where regular microsoft excel and word documents we use are saved
    Wife's account can access documents and save, but when testing and i try on my user, the file alterations have not been done.
    I log back into wife's account, open file, changes are there as previously saved, it's not being reflected on my user.
    Permissions set to read+write
    I tried a normal text document on my wife's account, saved it onto shared desktop, opened it from my user and that was fine.
    Please help

    Set up new user account for my wife
    shared my "desktop" where regular microsoft excel and word documents we use are saved
    Wife's account can access documents and save, but when testing and i try on my user, the file alterations have not been done.
    I log back into wife's account, open file, changes are there as previously saved, it's not being reflected on my user.
    Permissions set to read+write
    I tried a normal text document on my wife's account, saved it onto shared desktop, opened it from my user and that was fine.
    Please help

  • Adobe flash updater appears to lock user profile files in Windows 7

    Hello All,
    I don't own any Adobe products, but I wanted to put this up so that others who run into this issue can find it, and hopefully Adobe will look into it if it's common.
    This evening, I had just restarted my computer (Windows 7 RC), and after an usually long load time, I found myself loading into a profile other than my own.  Windows informed me that it has been unable to access my user profile and so had booted me into a temporary profile.  I noticed that the reason for being unable to access the profile was that it was being accessed (locked) by another program.  I rebooted.
    This time when I logged in, I was taken to my own profile, but before it loaded, I received a message from windows stating that it has been unable to open the user profile, and at the same time I saw a prompt from the Adobe Updater asking me if I wanted to upgrade to the next version of Adobe Flash.  After closing the dialogs, my profile contained everything for my desktop, but my windows settings appeared to have all been disabled (meaning Windows Aero was turned off and everything looked...odd--like an older version of windows squeezed into the updated Windows 7 interface).
    Taking a guess that the prompt from the Adobe updater may have been responsible for locking the profile while it was awaiting a response (somehow I guess it was running BEFORE windows loaded the user profile), I uninstalled all my adobe products and rebooted.
    Issue solved. Presumably, installing the update when you first see the prompt and not waiting for another time after a reboot would also bypass this issue.
    So it appears that the Update prompt locks the Windows user profile in Windows 7, which causes a problem because (maybe only on machines that don't auto login?) it appears to run before the profile loads: so it has a user profile file locked waiting for a response from the user, which can't come because the profile hasn't been loaded by Windows (so the user can't see the prompt), but Windows can't load the profile because the file is locked...sort of a soft dead lock (since I was sort of able to get in eventually).
    Wanted to get this out, and was also wondering if anyone else has seen this issue.
    Cheers,
    -jfc

    Trying to install FB 4.5 - comes up with this error on my machine - anyone have any concrete ideas on how to overcome this...
    I've tried rebooting, removing activex plugins etc but of no help....
    WARNING: DW031: Payload:{650C9D09-D5BD-4532-8BEE-01DBC1DF5537} Adobe Flash Builder 4.5 4.5.0.0 has been updated and has been selected for repair. The patch {CEAC4FFA-E7DE-4434-890A-F0AC7792DE5E} Adobe Flash Builder 4.5_4.5.1_AdobeFlashBuilder-mul 4.5.1.0 will be uninstalled now.
    WARNING: DW031: Payload:{650C9D09-D5BD-4532-8BEE-01DBC1DF5537} Adobe Flash Builder 4.5 4.5.0.0 has been updated and has been selected for repair. The patch {CEAC4FFA-E7DE-4434-890A-F0AC7792DE5E} Adobe Flash Builder 4.5_4.5.1_AdobeFlashBuilder-mul 4.5.1.0 will be uninstalled now.
    ----------- Payload: {551D0A52-5E4A-4898-9FFF-FEAA5E89585A} Adobe Flash Player 10 ActiveX 10.0.0.0 -----------
    ERROR: Error 1722.There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action NewCustomAction1, location: C:\DOCUME~1\nanunh\LOCALS~1\Temp\InstallAX.exe, command: -install activex -msi
    ERROR: Install MSI payload failed with error: 1603 - Fatal error during installation.
    MSI Error message: Error 1722.There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action NewCustomAction1, location: C:\DOCUME~1\nanunh\LOCALS~1\Temp\InstallAX.exe, command: -install activex -msi
    ERROR: DW050: The following payload errors were found during install:
    ERROR: DW050:  - Adobe Flash Player 10 ActiveX: Install failed
    Please search the above error/warning string(s) to find when the error occurred.
    These errors resulted in installer Exit Code mentioned below.
    Exit Code: 6 - Silent workflow completed with errors.
    [    1460] Mon Aug 15 17:52:20 2011  INFO
    *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

  • Don't know how or where to create user.js file so I can add script to allow copy and paste into a webbased email

    I am trying to compose an email from the email address on my web page. The email editor program (or Mozilla) doesn't allow me to do that. The instructions that Mozilla provided said to find the user.js file in Firefox's profile directory. I can't find such a file. I don't know where or how to create this file or how to write into it the lines that the instructions provided. I also don't know what url I am supposed to substitute for mozila.org that is in the lines of script.

    This was helpful. Now, to to do what I need to do I have to add something to the user.js file as per directions regarding ''setting prefs for Mozilla Rich Text Editing Demo'' to allow a copy and paste. It instructs me to change the URL from mozila.org to where I want to enable the function. I am not sure what that means. I am trying to to do something in the "back office" of my web site. I want to send an email from the web site's email. I am trying to copy and paste a pdf file into the body of the email but was not able to do it. I was directed to the setting prefs page. Do I change the location to the URL of my web site or the web site of the web host?

  • Despite home page set as default,prefs file being deleted. (twice) it still opens in welcome window, alongside is my home page tab,add on checking doesnt finish .

    everytime I open firefox. checking for add ons flashes up and disappears then welcome page opens, my home page tab is alongside it. I have uninstalled firefox. deleted the prefs file. instructed my privacy programme to ignore firefox all to no avail. I know I can edit user.js but not sure how. I can open it in notepad as instructed in help files but have no idea what to do next and what to edit.

    Do you have a file user.js in the Firefox Profile Folder?
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    Such a file isn't there by default, so if it is there then either you or other software or a Firefox extension has created it.
    *http://kb.mozillazine.org/user.js_file

  • Login items - not in user prefs

    My wonderful imac os x - tiger 10.4.7 opens 3 items (safari, mail and ichat) that are not in the startup items list.
    As the initial login takes ages I want to remove them, but as they don't appear in the list under accounts/login items I can't.
    I have tried adding them so they do appear and then deleting them, but that doesn't fix it, they still open on login.
    Any ideas how I can fix this.

    "Login Items" can be specified in at least three different places. The usual one (written to by the "Accounts" pref pane) is the "~/Library/Preferences/loginwindow.plist" file in each user's "home" folder, but if the items aren't appearing in the pref pane, they are probably listed in one of the other locations.
    The other user-specific file is in the "~/Library/Preferences/ByHost" folder, and is called the "loginwindow.xxx.plist" file, where the "xxx" usually represents the MAC address of the built-in ethernet card, so will vary from computer to computer. If present, try moving or deleting that file to see if that prevents the unwanted items from opening.
    The computer's main "/Library/Preferences" folder can also contain a "loginwindow.plist" file, but any items listed in that file will open at login for all users. "Admin" privileges will usually be required to remove or make changes to this file.
    Also, note that a computer's administrator can set up "login items" for "managed" users, through 'mcx_settings'. Again, this isn't something that an individual user can override themselves.
    This probably isn't what you are after, but unless explicitly prohibited in 'mcx_settings', it also is possible during any given log in to prevent login items from opening by holding down the "Shift" key while logging in, but it would be necessary to do this every time.

  • Create user.js file, create one.

    How do I create a user.js file on a MAC. I need to create this to add a code so I can cut and paste into the firefox browser.

    The user.js file is a plain text file. You should be able to create one with any program that can save a file in plain text format. Or, if you prefer, you could make a copy of prefs.js, rename it to user.js, then edit the contents to just what you want.
    (Sorry I can't be more specific, I am a Windows user.)

Maybe you are looking for

  • System folders on another drive other than boot drive

    hi, guys... does anyone know anything about moving your folders such as "documents, photos, movies, music" to an external drive or separate partition in snow leopard?  or how this might affect Lion? i've found some online documentation that shows you

  • How to reveal/open mailbox containing selected message in search results?

    A user is trying to find a message. She searches for the sender's email address and she sees the message in the search results and it is listed as being in a mailbox named "Prism". She browses through her list of mailboxes (local and on the server) a

  • Problem with swapDepth with press event

    Hi guys, Im getting confused with swapDepth for navigation buttons. I have a button mc's that use this for stacking but something weird happens on just the press event. I have tried to take away the press event but the problem makes it more difficult

  • How to debug a failed shopping cart transfer to ECC in classic mode

    Hello, I am using SRM 5 in classic mode, connected to ECC 6.0. I have an error message in the administrator monitor that tells me a transfer a shopping cart to ECC has failed. "Shopping cart 1000000123: Error creating the follow-on document" (Message

  • 8.02 upgrade froze my phone

    I downloaded the 8.02 last night and its now swapping through a blank blue screen and the apple screen on my iphone 5S, how do I fix this?