Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HiRez

macrumors 603
Original poster
Jan 6, 2004
6,250
2,576
Western US
Hi, I'm trying to use user defaults with AppleScript Studio. I'm setting up user defaults like so (I edited this function down, this is just one of many):

Code:
on will finish launching theObject
	try
		tell user defaults
			make new default entry at end of default entries with properties {name:DEFAULT_CLEAN_PREFIX_KEY, contents:DEFAULT_CLEAN_PREFIX}
		end tell		
		call method "synchronize" of object user defaults
	on error errMsg number errNum
		display dialog "Error registering user defaults: " & errMsg
	end try
end will finish launching

When the variable DEFAULT_CLEAN_PREFIX is a string of 1 or more characters, this works fine: the default entry is created. The problem is when I want to set the initial value to "" (an empty string). In this case, user defaults seems to detect this and does not make a defaults entry for that key. This royally screws up my script later when I go to access that value (AppleScript complains with an error of course).

So why can't I make a new default entry with a blank string? This seems like it might be quite a common thing that people would want to do. Is there some special AppleScript keyword I'm missing that would help me out here ("null" does not work, it gives me the memory location of null when I try to access it)? Now I can work around this by setting the default initially to some string of 1+ characters, then immediately rewriting the default as "". That works but it sure seems like an ugly hack that shouldn't be necessary (then again, I'm finding that AppleScript requires many ugly hacks on a regular basis). Any ideas? TIA.

EDIT: OK ignore this whole thing, I guess. After deleting the prefs file a few times and recompiling it seems to be working now (even though I changed nothing). Something is definitely goofy but I can't pin it down. *sigh* AppleScript is always so wonderful and so frustrating at the same time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.