Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Save user-defaults (first post)



Hello,

I recently tackled a very similar problem and here is the code I came up
with:

-------------------- BEGIN CODE --------------------

(* when the program launches, we check to see if a preference file
exists
and read the entry to populate a text field *)

on awake from nib
	set readPrefs to ""
	tell user defaults
		if default entry "lastUser" exists then
			set readPrefs to contents of default entry
"lastUser" as string
		end if
	end tell
	
	tell window named "w1"
		set content of text field "userID" to readPrefs
	end tell
	
end awake from nib


(*here we reset or set the preference after an event handler like a
button click*)
try
tell user defaults
	if default entry "lastUser" exists then
		set contents of default entry "lastUser" to theID
	else
		make new default entry at end of default entries with
properties {name:"lastUser", contents:theID}
	end if
end tell
quit
on error
display dialog "Prefs could not be set"
end try

-------------------- END CODE --------------------

Also keep in mind that you have to register an identifier for your
program in preferences list style (e.g. com.company.programName) in
Xcode under Targets>"Program Name">Info.plist entries>Basic Information
where "Program Name" is the name of your program.

Hope this helps,

Brian Sheehan

>Subject: Save user-defaults  (first post)
>To: email@hidden
>Message-ID: <p06020402be707f0e905d@[10.5.100.102]>
>Content-Type: text/plain; charset="us-ascii" ; format="flowed"
>
>Hello and thanks ahead of time to anyone who can help.
>I have been playing with applescript for years but only recently 
>tried Applescript studio.
>I have a simple application made that will backup files from the 
>desktop and documents folder to a folder on the users 10.3 server 
>users folder.
>
>They have to enter the ip address  and username and password in a 
>text field on the window.
>I would like for the ip address and username to be saved and remain 
>when they launch the program again.
>
>I've looked at the Archive Maker example and can't seem to move the 
>concepts from it to my program.
>
>Does someone have a very basic example that will store the text 
>entered in the text fields on subsequent uses of the program.
>
>Any help appreciated.
>
>I am using only one script in the application with simple variable 
>names like ipnumb, userpw, and usern
>
>on should quit after last window closed theObject
>      tell user defaults
>            make new default entry at end of default entries with 
>properties {name:"ipnumber", contents:ipnumb}
>            register
>      end tell
>      quit
>end should quit after last window closed
>
>on opened theObject
>      tell user defaults
>            set ipnumb to contents of default entry "ipnumber"
>      end tell
>end opened


---------------------------------------
Brian Sheehan
IS Department
401.726.0800 x 2558
---------------------------------------
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.