create a plist file

trying to create a simple plist file but when i pass the userName to the file_path it tells me it does not expect identifier. please help. thks

tell application “System Events”
set userName to name of current user as string

end tell

set startup_path to path to startup disk as string
set file_path to startup_path & “Users:” userName":Library:Preferences:" & “myapp.plist”
set the_file to (open for access file file_path with write permission)

set eof of the_file to 0

Hello merdrum21,

This is just a guess, but have you tried enclosing your “Tell” statement in a “Try” statement? This may work.

Sincerely,

Variable as the shade

Instead of

set file_path to startup_path & "Users:" userName":Library:Preferences:" & "myapp.plist"

try

set file_path to startup_path & "Users:" & userName & ":Library:Preferences:myapp.plist"

By the way, there’s no reason to invoke System Events; the “path to” command is part of Standard Additions, so

set file_path to path to preferences folder as string
set target_file to file_path & "myapp.plist"

gets you the path to your prefs file.

Apple has made this very easy by including the “defaults” command line tool:

So for your own preferences, just use:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

I have used this script, and it works great.

however, I have attached the script to a button which writes a value to “the_value”, but i would like to read “the_value” on a subsequent button press, and pass it to an “if” statement.

does that make sense??

please help.

i solved it, using this script:


	set theOutputFolder to path to preferences folder as Unicode text
	set thePListPath to POSIX path of (theOutputFolder & "SafariSafe.plist")
	tell application "System Events"
		tell property list file thePListPath
			tell contents
				set u to the value of property list item "safe"
			end tell
		end tell
	end tell
	
	if u is "0" then
		set v to display dialog "you have already made safari safe" buttons {"OK"} default button 1
		if the button returned of v is "OK" then error number -128
	end if

from this webpage:
http://www.mactech.com/articles/mactech/Vol.22/22.03/StoringandAccessingData/index.html