two syntax issues while doing shell script

I’m making a simple preferences script, but I can’t figure out how to display the preferences in a text field:


on launched theObject
	tell window "main"
		set theUsername to do shell script "defaults read com.zomplog.preferences 'username'"
		set contents of text field "username" to theUsername
	end tell
end launched

I think the line “set The Username to do shell script” is wrong, but does anyone know the right syntax?

Model: Imac G5
Browser: Safari 412, Xcode 2.1
Operating System: Mac OS X (10.4)

Is this for reading the preferences of the app that is running the script or for reading third-party preferences? If it is the first, you should use the built-in defaults commands for reading prefs. If it is the latter, then you need to put in the whole path to the file (except the final “.plist” extension):

set the_pref_file to quoted form of ((POSIX path of (path to preferences folder)) & "com.zomplog.preferences")
set theUsername to do shell script "defaults read " & the_pref_file & " 'username'"

Jon

I don’t think the path is the problem, because I was able to write to the file using the same method:


	if name of theObject is "settingssubmit" then --> settings button
		tell window "main"
			set theUsername to contents of text field "username"
			do shell script "defaults write com.zomplog.preferences 'username'" & space & "'" & theUsername & "'" --> nice Gerben Hack
		end tell
		beep
	end if
end clicked

The problem must be the “on launched” part, cos when I attach this behaviour to an "on clicked " event, everything works fine.

I don’t really know what I should do in interface builder to make the “on launched” command work. Any suggestions?