Problems with user defaults

Hi guys im having trouble with a specfic piece of code in my program, for some reason it does not want to accept the AutoDisarm entry in the use defaults, i tested the if statement using just 1 = 1 which works of course but for some reason it doesnt want to accept this entry.

line 244

if (content of default entry "AutoDisarm" of user defaults) is true then
-- MultiAlarm.applescript
-- MultiAlarm
-- Created by semaja2 on 13/04/2006

--Name of Application
property appName : "MultiAlarm"
property Readme : false
property OEM : false
property OEMName : "BETA Corp"
property OEMWeb : "http://www.semaja2.net/"
property DONATEWeb : "http://www.semaja2.net/donations"
--*******************--Alarm Variables--***************--
--Used to keep alarm going
property alarmLocked : false
property UseSMS : ""
property UseNonSMS : ""
property DisarmReset : true
--Used in variables to explain is alarm is armed
property alarmActivated : false
---***************--External Scripting related--***********--
--What script to load externally
property alertScript : ""
--*****************--Sensor--************************--
property UniMotion : true
property thisHere : ""
property theUpperX : ""
property theLowerX : ""
property theUpperY : ""
property theLowerY : ""
property theNewX : ""
property theNewY : ""
--******************--Sounds--*********************---
--Sets old Volume
property theOldVolume : ""
--Sets what the Volume should be set to on alert
property AlertVolume : ""
property theArming : ""
--Selects what sound to alert with
property alert_snd : ""
--*******************--Lockscreen Variables---************--
--Paths to image for backround
property LockImage : ""
property picPath : ""
--Secure Key for disarming of alarm
property SecureKey : ""
--******************--Password--***********************--
property the_password : ""
property thePass : ""
property myName : ""
property AdminKey : ""

-------------------------------------------When Application loads---------------------------------------------
on launched theObject
	--Username for administrative powers
	set myName to do shell script "whoami"
	log "MultiAlarm: User " & myName & " began MultiAlarm"
	log "MultiAlarm: load started"
	---------------Sets paths---------------------
	set thisHere to path to me
	set thisHere to quoted form of (POSIX path of thisHere)
	--------------Checks Path for Volumes---------------
	if thisHere contains "/Volumes/MultiAlarm" then
		display dialog (localized string "ERROR_DiskImageRun" from table "Localizable") buttons {"Ok"}
		log "MultiAlarm: Failed Load, detected load from a disk image"
		quit
	end if
	------------Makes Preferences-------------
	try
		log "MultiAlarm: Setting Prefrence file up"
		tell user defaults
			-- make defaults values if they don't exist
			-------------------------------
			--MultiAlarm Vital Options 
			-------------------------------
			--Variable for sensitivity of alarm
			make new default entry at end of default entries with properties {name:"alarmSensitivity", content:3}
			--Alow use of KILLALARM function
			make new default entry at end of default entries with properties {name:"scriptAccess", content:false}
			--UniMotion
			make new default entry at end of default entries with properties {name:"UniMotion", content:false}
			--Sleep Control
			make new default entry at end of default entries with properties {name:"SleepControl", content:false}
			--About Box
			make new default entry at end of default entries with properties {name:"TOC", content:false}
			--Auto Arm
			make new default entry at end of default entries with properties {name:"AutoArmTime", content:0}
			--Auto Arm
			make new default entry at end of default entries with properties {name:"AutoDisarm", content:false}
			--Non SMS
			make new default entry at end of default entries with properties {name:"UseNonSMS", content:false}
			--Alert Delay
			make new default entry at end of default entries with properties {name:"AlertDelay", content:0}
			-------------------------------
			--Screen Lock Options   --
			-------------------------------
			--Activate the lock when armed
			make new default entry at end of default entries with properties {name:"preLock", content:false}
			--Location of image for screen-lock
			make new default entry at end of default entries with properties {name:"LockImage", content:""}
			--Use a custom backround option
			make new default entry at end of default entries with properties {name:"CustomBackround", content:false}
			--Max attempts for screen-lock before it locks out
			make new default entry at end of default entries with properties {name:"MaxAttempts", content:5}
			--Lockout time (seconds)
			make new default entry at end of default entries with properties {name:"BlockTime", content:5}
			--Contains the status (Used to pass status between MultiAlarm and Screen-Lock
			make new default entry at end of default entries with properties {name:"state", content:"disarmed"}
			-------------------------------
			--Other Alert Functions --
			-------------------------------
			--Use External Script
			make new default entry at end of default entries with properties {name:"EnableAlertScript", content:false}
			--Location of external script
			make new default entry at end of default entries with properties {name:"alertScript", content:""}
			-------------------------EMAIL----------------------------
			--Use email as a alert
			make new default entry at end of default entries with properties {name:"emailAlert", content:false}
			--Email content
			make new default entry at end of default entries with properties {name:"emailAlertMsg", content:"Theft in progress"}
			--Email Address
			make new default entry at end of default entries with properties {name:"emailAlertAddress", content:"example@example.com"}
			-----------------------SOUND------------------
			--Sound to be alerted with
			make new default entry at end of default entries with properties {name:"AlertMP3", content:"lost.mp3"}
			--Volume of sound alert
			make new default entry at end of default entries with properties {name:"SoundAlertVolume", content:100}
			--Play arm sound
			make new default entry at end of default entries with properties {name:"ArmSound", content:true}
			--Play Disarm Sound
			make new default entry at end of default entries with properties {name:"DisarmSound", content:true}
			-----------------------iSight------------------
			--Use the iSight camera
			make new default entry at end of default entries with properties {name:"iSight", content:false}
			--Save local copy
			make new default entry at end of default entries with properties {name:"iSightLocalCopy", content:false}
			--Save iDisk copy
			make new default entry at end of default entries with properties {name:"iSightiDiskCopy", content:false}
			--Where to copy image to
			make new default entry at end of default entries with properties {name:"iSightSave", content:""}
			--use a FTP upload
			make new default entry at end of default entries with properties {name:"FTP", content:false}
			--FTP Password
			make new default entry at end of default entries with properties {name:"FTPPass", content:"Pass"}
			--FTP Directory
			make new default entry at end of default entries with properties {name:"FTPDir", content:"/"}
			--FTP User
			make new default entry at end of default entries with properties {name:"FTPUser", content:"User"}
			--FTP Address
			make new default entry at end of default entries with properties {name:"FTPSite", content:"ftp://ftp.com"}
			log "MultiAlarm: Preference file ready to load"
		end tell
	on error errMsg number errNum
		log "Error " & errNum & ": " & errMsg
		display dialog "Error " & errNum & ": " & errMsg buttons {"Ok"}
	end try
	------------Reads Preferences-------------
	-------------------------------
	--Screen Lock Variables --
	-------------------------------
	SetLockImage()
	SetPass()
	-------------------------------
	--Sound Alert Variables --
	-------------------------------
	--Alert Sounds
	--Arm Disarm Sounds
	if (content of default entry "ArmSound" of user defaults) or (content of default entry "DisarmSound" of user defaults) is true then
		set theArming to load sound "arm.wav"
		log "MultiAlarm: Arm/Disarm Sounds Activated"
	end if
	--Alert Sounds
	SetAlertSounds()
	-------------------------------
	--SMS CHECKS Functions
	-------------------------------
	log "MultiAlarm: SMS Engine - UniMotion"
	--Checks if UseNonSMS should be set
	--Runs a cmd to check is pmset -g contains "sms 1" if it fails to do so it will show error screen
	try
		do shell script "/usr/bin/pmset -g | /usr/bin/grep 'sms' | /usr/bin/colrm 1 8"
		set UseSMS to true
	on error
		set UseSMS to false
	end try
	log "MultiAlarm: SMS Sensor Status :" & UseSMS
	--Checks if user wants SMS Sensor
	try
		set UseNonSMS to content of default entry "UseNonSMS" of user defaults
		log "MultiAlarm: Use nonsms sensors :" & UseNonSMS
	on error
		display dialog (localized string "ERROR_ExtraAlerts" from table "Localizable") buttons {"Ok"}
	end try
	-------------------------------
	--Finished Load 
	-------------------------------
	log "MultiAlarm: successfully loaded"
	--Displays Welcome Screens
	try
		--log "test 1"
		set Var to content of default entry "TOC" of user defaults
		--log Var
		if Var is false then
			--log "2"
			set visible of window "WelcomeWindow" to true
			--log "3"
			if OEM is true then
				--log "4"
				display dialog "This product was brought to you by " & OEMName attached to window "WelcomeWindow" buttons {"Ok"}
			end if
		end if
	on error
		set visible of window "WelcomeWindow" to true
		if OEM is true then
			display dialog "This product was brought to you by " & OEMName attached to window "WelcomeWindow" buttons {"Ok"}
		end if
	end try
	
end launched

--When Application is Idle
on idle theObject
	if alarmActivated is true then
		--log (content of default entry "DisarmSound" of user defaults)
		call method "synchronize" of (call method "standardUserDefaults" of class "NSUserDefaults")
		--Checks the screenlock codes
		set theState to (content of default entry "state" of user defaults)
		set alertDelay to (content of default entry "AlertDelay" of user defaults)
		set autoDisarm to (content of default entry "AutoDisarm" of user defaults)
		log autoDisarm
		set SMS to (content of default entry "UniMotion" of user defaults)
		
		if theState contains "disarmed" then
			alarmDeactivate(1)
			
			--else
			
			--Checks if alarm has been set off
		else if theState contains "activate" then
			if alertDelay is greater than 0 and alarmLocked is false then
				--log "Activate"
				log alarmLocked
				alarmactivation()
			end if
			if (content of default entry "AutoDisarm" of user defaults) is true then
				--if 1 = 1 then
				--runs motion cmd to find x and y axis
				set theNewCoords to do shell script thisHere & "Contents/Resources/UniMotion"
				if theNewCoords is not "" then
					set {theNewX, theNewY} to getXY(theNewCoords)
					set theNewX to theNewX + 1000
					set theNewY to theNewY + 1000
					--Checks the x and y axis for change if change is found it will start the process
					--if theNewX is not greater than theUpperX or theNewX is not less than theLowerX or theNewY is not greater than theUpperY or theNewY is not less than theLowerY then
					if theNewX is greater than theUpperX or theNewX is less than theLowerX or theNewY is greater than theUpperY or theNewY is less than theLowerY then
						
						alarmAlert(1)
						log "Alert1"
						beep
						--log "MultiAlarm: SMS Sensors resetting alarms"
						--log "MultiAlarm: Sensor Info - X: " & theNewX & "Y: " & theNewY
						--Stops ScreenLock
						--do shell script "killall screenlock"
						--Fixes dock
						--do shell script "killall -CONT Dock"
						--set alarmLocked to false
						--log "MultiAlarm: Alarm Killed"
					end if
				end if
				
			else
				alarmAlert(1)
				log "Alert2"
				beep
			end if
		else if alarmLocked is false then
			
			if (content of default entry "UseNonSMS" of user defaults) is true then
				set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'")
				if idleTime < "1" then
					log "MultiAlarm: NonSMS Sensors activating alarms " & idleTime
					--Activates Lock
					set alarmLocked to true
					if (content of default entry "preLock" of user defaults) is false then
						activateLock(1)
						log "MultiAlarm : Starting Screen-Lock"
					else
						alarmactivation()
					end if
					--alarmactivation()
				end if
			end if
			--checks if SMS is avaialable
			if UseSMS is true and (content of default entry "UniMotion" of user defaults) is true then
				--runs motion cmd to find x and y axis
				set theNewCoords to do shell script thisHere & "Contents/Resources/UniMotion"
				if theNewCoords is not "" then
					set {theNewX, theNewY} to getXY(theNewCoords)
					set theNewX to theNewX + 1000
					set theNewY to theNewY + 1000
					--Checks the x and y axis for change if change is found it will start the process
					if theNewX is greater than theUpperX or theNewX is less than theLowerX or theNewY is greater than theUpperY or theNewY is less than theLowerY then
						log "MultiAlarm: SMS Sensors activating alarms"
						log "MultiAlarm: Sensor Info - X: " & theNewX & "Y: " & theNewY
						--Activates Lock
						set alarmLocked to true
						if (content of default entry "preLock" of user defaults) is false then
							activateLock(1)
						else
							alarmactivation()
						end if
						--alarmactivation()
					end if
				end if
			end if
		end if
		
		
		--AutoArm System
	else if alarmActivated is false then
		if (content of default entry "AutoArmTime" of user defaults) is greater than 0 then
			set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'") as number
			if idleTime > (content of default entry "AutoArmTime" of user defaults) then
				log "MultiAlarm: Arming at " & idleTime
				alarmActivate(1)
			end if
		end if
	end if
	
end idle


---------------Interface Functions---------------

--Menu Items

on choose menu item theObject
	set n to name of theObject
	call method "synchronize" of (call method "standardUserDefaults" of class "NSUserDefaults")
	
	--Arm Menu item
	if n is "Arm" then
		if alarmActivated is true then
			display dialog (localized string "ERROR_AlarmArmed" from table "Localizable") buttons {"Ok"}
		else
			--Checks if keychain exists
			if passwordCheck("MultiAlarm") is equal to 1 then
				alarmActivate(1)
			else
				set visible of window "setpass" to true
				display dialog (localized string "ERROR_ArmingPass" from table "Localizable") attached to window "setPass" buttons {"Ok"}
			end if
		end if
		
		--Disarm Menu Item
	else if n is "Disarm" then
		--Checks if alarm was armed or not
		if alarmActivated is true then
			set visible of window "unlock" to true
		else
			display dialog (localized string "ERROR_NotArmed" from table "Localizable") buttons {"Ok"}
		end if
		
		--Secure exit item
	else if n is "alarmExit" then
		--checks if alarm is activated
		if alarmActivated is true then
			--If alarm is armed it will password prompt
			set visible of window "quitCheck" to true
		else
			--If alarm was not armed it will quit
			quit
		end if
	else if n is "Lock" then
		activateLock(1)
	else if n is "Support" then
		open location "http://support.semaja2.net"
	end if
end choose menu item

--Clicked objects

on clicked theObject
	set n to name of theObject
	call method "synchronize" of (call method "standardUserDefaults" of class "NSUserDefaults")
	if n is "KILLALARM" then
		try
			if alarmActivated is true then
				if (content of default entry "scriptAccess" of user defaults) is true then
					--Runs deactivate protocol
					alarmDeactivate(1)
					--Stops ScreenLock
					do shell script "killall screenlock"
					--Fixes dock
					do shell script "killall -CONT Dock"
					log "MultiAlarm: Alarm Killed"
				end if
			end if
		on error
			log "MultiAlarm: Alarm Killage Failed"
		end try
		--DISARM BUTTON
	else if n is "Disarm" then
		
		set c to content of text field "secureDisarm" of window "unlock"
		set the_password to c
		set the content of text field "secureDisarm" of window "unlock" to ""
		if the_password = getPW("MultiAlarm") then
			set visible of window "unlock" to false
			alarmDeactivate(1)
			log "MultiAlarm: Disarmed"
		else
			log "MultiAlarm: Incorrect Password"
			display dialog (localized string "ERROR_BadPass" from table "Localizable") attached to window "unlock" buttons {"Ok"}
		end if
		
		
		--Exit System		
	else if n is "exit" then
		
		set c to content of text field "secureExit" of window "quitCheck"
		set the_password to c
		set the content of text field "secureExit" of window "quitCheck" to ""
		if the_password = getPW("MultiAlarm") then
			set alarmActivated to false
			quit
		else
			display dialog (localized string "ERROR_BadPass" from table "Localizable") attached to window "quitCheck" buttons {"Ok"}
		end if
		
		--Sensitivity Setting
	else if n is "setSensitvity" then
		
		try
			set sensitivity to content of default entry "alarmSensitivity" of user defaults
		on error
			display dialog (localized string "ERROR_SetSens" from table "Localizable") attached to window "settings" buttons {"Ok"}
		end try
		
		
		--Change Password
	else if n is "password" then
		
		--Checks if item already exists
		if passwordCheck("MultiAlarm") is equal to 1 then
			set visible of window "setpass" to false
			set visible of window "setCheck" to true
			log "MultiAlarm: Previous password found"
		else
			set visible of window "setpass" to true
			set visible of window "setCheck" to false
			log "MultiAlarm: No previous password found"
		end if
		
		
	else if n is "confirm" then
		
		set c to content of text field "secureOld" of window "setCheck"
		set the_password to c
		set the content of text field "secureOld" of window "setCheck" to ""
		if the_password = getPW("MultiAlarm") then
			set visible of window "setpass" to true
			set visible of window "setCheck" to false
			log "MultiAlarm: Correct Password entered"
		else
			log "MultiAlarm: Incorrect password entered"
			display dialog (localized string "ERROR_BadPass" from table "Localizable") attached to window "setCheck" buttons {"Ok"}
			beep 2
		end if
		
	else if n is "Set" then
		--try
		set firstpass to content of text field "setpass1" of window "setpass"
		set newPWD to content of text field "secureSet" of window "setpass"
		if firstpass contains newPWD then
			log "MultiAlarm: Passwords match, setting password"
			setPassword(newPWD, "MultiAlarm")
			--beep 1
			display dialog (localized string "PROMPT_SetPass" from table "Localizable") attached to window "setpass" buttons {"Ok"}
			set visible of window "setpass" to false
			log "MultiAlarm: Password was set"
		else
			display dialog (localized string "ERROR_NoMatchPass" from table "Localizable") attached to window "setpass" buttons {"Ok"}
			log "MultiAlarm: Password did not match"
		end if
		SetPass()
		--on error
		--	display dialog (localized string "ERROR_Keychain" from table "Localizable") attached to window "setpass" buttons {"Ok"}
		--end try
		
	else if n is "setScript" then
		if (content of default entry "EnableAlertScript" of user defaults) is true then
			choose file with prompt (localized string "FILE_Script" from table "Localizable") without invisibles
			tell user defaults to set content of default entry "alertScript" to (result as Unicode text)
			log "MultiAlarm: Script set to - " & (content of default entry "alertScript")
		end if
	else if n is "setLockImage" then
		if (content of default entry "CustomBackround" of user defaults) is true then
			choose file with prompt (localized string "FILE_Backround" from table "Localizable") without invisibles
			tell user defaults to set content of default entry "LockImage" to (result as Unicode text)
			log "MultiAlarm: Lock image set to - " & (content of default entry "LockImage")
		end if
		SetLockImage()
		
	else if n is "iSightLocalCopy" then
		if (content of default entry "iSightLocalCopy" of user defaults) is true then
			choose folder with prompt (localized string "FILE_iSight" from table "Localizable") without invisibles
			tell user defaults to set content of default entry "iSightSave" to (POSIX path of (result as Unicode text))
		end if
	else if n is "AutheticateButton" then
		set c to content of text field "MultiAlarmKey" of window "Autheticate"
		set the_password to c
		set the content of text field "MultiAlarmKey" of window "Autheticate" to ""
		if the_password = getPW("MultiAlarm") then
			try
				set newPWD to content of text field "AdminKey" of window "Autheticate"
				setPassword(newPWD, "AdminKey")
				set visible of window "Autheticate" to false
				display dialog (localized string "PROMPT_Auth" from table "Localizable") attached to window "settings" buttons {"Ok"}
			on error
				display dialog (localized string "ERROR_Auth" from table "Localizable") attached to window "Autheticate" buttons {"Ok"}
			end try
			if passwordCheck("AdminKey") is equal to 1 then
				try
					set AdminKey to getPW("AdminKey")
					log "MultiAlarm: AdminKey retrived"
				on error
					log "MultiAlarm: AdminKey Could not be retrived"
					display dialog (localized string "ERROR_AdminAuth" from table "Localizable") buttons {"Ok"}
				end try
			else
				display dialog (localized string "ERROR_AdminAuth" from table "Localizable") buttons {"Ok"}
			end if
		else
			display dialog (localized string "ERROR_BadPass" from table "Localizable") attached to window "Autheticate" buttons {"Ok"}
		end if
	else if n is "SleepControl" then
		if (content of default entry "SleepControl" of user defaults) is true then
			set visible of window "Autheticate" to true
			display dialog (localized string "PROMPT_InsomniaIntel" from table "Localizable") buttons {"Ok"}
			display dialog (localized string "PROMPT_Insomnia" from table "Localizable") attached to window "Autheticate" buttons {"Ok"}
		end if
	else if n is "LogoButton" then
		open location OEMWeb
		
	else if n is "WelcomeContinue" then
		set visible of window "WelcomeWindow" to false
		set visible of window "FinishedWindow" to true
		
	else if n is "WizardBack" then
		set visible of window "FinishedWindow" to false
		set visible of window "WelcomeWindow" to true
		
	else if n is "WizardPref" then
		set visible of window "settings" to true
		set visible of window "FinishedWindow" to false
		tell user defaults to set content of default entry "TOC" to true
		
	else if n is "WizardFinished" then
		set visible of window "FinishedWindow" to false
		set visible of window "WelcomeWindow" to false
		tell user defaults to set content of default entry "TOC" to true
	else if n is "usenonsmstick" then
		try
			set UseNonSMS to content of default entry "UseNonSMS" of user defaults
			log "MultiAlarm: Use nonsms sensors -" & UseNonSMS
		on error
			display dialog (localized string "ERROR_ExtraAlerts" from table "Localizable") buttons {"Ok"}
		end try
	else if n is "ClearLogs" then
		try
			log "MultiAlarm: Attempting to clear log file"
			do shell script "rm " & thisHere & "Contents/Resources/log.txt"
			do shell script "echo 'This is the log file for MultiAlarm' > " & thisHere & "Contents/Resources/log.txt"
			log "MultiAlarm: Logs cleared"
			display dialog (localized string "PROMPT_LogsCleared" from table "Localizable") buttons {"Ok"} attached to window "LogWindow"
		on error
			log "MultiAlarm: Error occured while clearing log files"
			display dialog (localized string "ERROR_FailedLogClear" from table "Localizable") buttons {"Ok"} attached to window "LogWindow"
		end try
	else if n is "prelockOption" then
		if (content of default entry "alertDelay" of user defaults) is greater than 0 then
			display dialog (localized string "ERROR_AlertDelay" from table "Localizable") attached to window "settings" buttons {"Ok"}
			tell user defaults to set content of default entry "PreLock" to false
			call method "synchronize" of (call method "standardUserDefaults" of class "NSUserDefaults")
		end if
	else if n is "Donate" then
		open location DONATEWeb
	end if
end clicked

--Window became activated

on became key theObject
	set n to name of theObject
	if n is "LogWindow" then
		set theURLOfMe to (path to me)
		set applescriptPathToMe to (theURLOfMe) as string
		set LogFile to applescriptPathToMe & "Contents:Resources:log.txt"
		set contents of text view "LogBox" of scroll view "LogBox" of window "LogWindow" to (read file LogFile)
	else if n is "ReadmeFile" then
		tell user defaults to set content of default entry "TOC" to true
	else if n is "settings" then
		try
			tell image view "iSightView" of tab view item "iSight" of tab view "SettingsView" of window "settings"
				set oldImage to its image
				set its image to load image "isight.jpg"
				try
					delete oldImage
				end try
			end tell
		on error
			log "MultiAlarm: Failed to update image"
		end try
	end if
end became key

--When program is exiting check if it is allowed to

on should quit
	if alarmActivated is true then
		--If alarm is armed it will password prompt
		set visible of window "quitCheck" to true
		return 0
	else
		--If alarm was not armed it will quit
		return 1
	end if
end should quit

on should close theObject
	log "MultiAlarm: Recalling preference file"
	call method "synchronize" of (call method "standardUserDefaults" of class "NSUserDefaults")
end should close

on end editing theObject
	(*Add your script here.*)
end end editing

on update menu item theObject
	(*Add your script here.*)
end update menu item

on begin editing theObject
	set n to name of theObject
	if n is "FTPPassword" then
		display dialog (localized string "PROMPT_FTPEncrypt" from table "Localizable") attached to window "settings" buttons {"Ok"}
	end if
end begin editing

on selection changed theObject
	
	set n to name of theObject
	if n is "combo" then
		try
			set alarmSound to (get current item of theObject)
			if alarmSound is not equal to 5 then
				if alarmSound = 1 then
					set alert to (load sound "caralarm.mp3")
				else if alarmSound = 2 then
					set alert to (load sound "voice.mp3")
				else if alarmSound = 3 then
					set alert to (load sound "silent.mp3")
				else if alarmSound = 4 then
					set alert to (load sound "lost.mp3")
				end if
				play alert
				log "2"
				
			end if
		on error
			log "MultiAlarm: Sound file could not be played"
		end try
		SetAlertSounds()
	end if
end selection changed

on action theObject
	set n to the name of theObject
	if n is "AlertDelayOption" then
		if (content of default entry "prelock" of user defaults) is true then
			display dialog (localized string "ERROR_PreLock" from table "Localizable") attached to window "Settings" buttons {"Ok"}
			tell user defaults to set content of default entry "AlertDelay" to 0
			call method "synchronize" of (call method "standardUserDefaults" of class "NSUserDefaults")
			
		end if
	end if
end action

on opened theObject
	set n to name of theObject
	if n is "settings" then
		---------------Sets paths---------------------
		set thisHere to path to me
		set thisHere to quoted form of (POSIX path of thisHere)
		try
			set motionEngine to thisHere & "Contents/Resources/UniMotion"
			do shell script motionEngine
			set theCoords to do shell script motionEngine
			--display dialog "Congragulations, Your Apple Laptop can use SMS aware applications" buttons {"Ok"} attached to window "Main"
			set enabled of button "SMSEnable" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings" to true
			set enabled of slider "SMSSens" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings" to true
			--setStatus("Sensor-ON.icns", "SMSMain")
			set newImage to load image "Sensor-ON.icns"
			tell image view "SMSStaticon" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings"
				set oldImage to its image
				set its image to newImage
				try
					delete oldImage
				end try
			end tell
			set contents of text field "Status" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings" to "Sudden Motion Sensor Detected, Coordinates: " & theCoords
			log "SenChecker: Sudden Motion Sensor Detected, Coordinates: " & theCoords
		on error
			--display dialog "Congragulations, Your Apple Laptop can use SMS aware applications" buttons {"Ok"} attached to window "Main"
			set enabled of button "SMSEnable" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings" to false
			set enabled of slider "SMSSens" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings" to false
			--setStatus("Sensor-ON.icns", "SMSMain")
			set newImage to load image "Sensor-OFF.icns"
			tell image view "SMSStaticon" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings"
				set oldImage to its image
				set its image to newImage
				try
					delete oldImage
				end try
			end tell
			set contents of text field "Status" of box "SMS" of tab view item "alarms" of tab view "SettingsView" of window "settings" to "Sudden Motion Sensor Detected, Coordinates: " & theCoords
			log "SenChecker: Sudden Motion Sensor Detected, Coordinates: " & theCoords
			--display dialog "Sorry, Your Apple Laptop can not use SMS aware application" buttons {"Ok"} attached to window "Main"
			--set enabled of button "AppList" of window "SMSMain" to false
			--set contents of text field "Status" of window "SMSMain" to "Sudden Motion Sensor Not Detected"
			log "SenChecker: Sudden Motion Sensor Not Detected"
		end try
	else if n is "WelcomeWindow" then
		---------------Sets paths---------------------
		set thisHere to path to me
		set thisHere to quoted form of (POSIX path of thisHere)
		try
			set motionEngine to thisHere & "Contents/Resources/UniMotion"
			do shell script motionEngine
			set theCoords to do shell script motionEngine
			--display dialog "Congragulations, Your Apple Laptop can use SMS aware applications" buttons {"Ok"} attached to window "Main"
			set enabled of button "SMSEnable" of box "SMS" of window "WelcomeWindow" to true
			set enabled of slider "SMSSens" of box "SMS" of window "WelcomeWindow" to true
			--setStatus("Sensor-ON.icns", "SMSMain")
			set newImage to load image "Sensor-ON.icns"
			tell image view "SMSStaticon" of box "SMS" of window "WelcomeWindow"
				set oldImage to its image
				set its image to newImage
				try
					delete oldImage
				end try
			end tell
			set contents of text field "Status" of box "SMS" of window "WelcomeWindow" to "Sudden Motion Sensor Detected, Coordinates: " & theCoords
			log "SenChecker: Sudden Motion Sensor Detected, Coordinates: " & theCoords
		on error
			--display dialog "Congragulations, Your Apple Laptop can use SMS aware applications" buttons {"Ok"} attached to window "Main"
			set enabled of button "SMSEnable" of box "SMS" of window "WelcomeWindow" to false
			set enabled of slider "SMSSens" of box "SMS" of window "WelcomeWindow" to false
			--setStatus("Sensor-ON.icns", "SMSMain")
			set newImage to load image "Sensor-OFF.icns"
			tell image view "SMSStaticon" of box "SMS" of window "WelcomeWindow"
				set oldImage to its image
				set its image to newImage
				try
					delete oldImage
				end try
			end tell
			set contents of text field "Status" of box "SMS" of window "WelcomeWindow" to "Sudden Motion Sensor Detected, Coordinates: " & theCoords
			log "SenChecker: Sudden Motion Sensor Detected, Coordinates: " & theCoords
			--display dialog "Sorry, Your Apple Laptop can not use SMS aware application" buttons {"Ok"} attached to window "Main"
			--set enabled of button "AppList" of window "SMSMain" to false
			--set contents of text field "Status" of window "SMSMain" to "Sudden Motion Sensor Not Detected"
			log "SenChecker: Sudden Motion Sensor Not Detected"
		end try
	end if
end opened





----------------Functions------------
on changeStatus(imagename)
	set newImage to load image imagename
	tell me
		set icon image to newImage
	end tell
end changeStatus

on SetLockImage()
	try
		--Sets Variables for Screen-Lock
		if (content of default entry "CustomBackround" of user defaults) is true then
			set LockImage to content of default entry "LockImage" of user defaults
			set picPath to quoted form of (POSIX path of LockImage)
		else
			set picPath to thisHere & "Contents/Resources/Default.jpg"
		end if
		log "MultiAlarm: Background set to: " & picPath
	on error
		log "MultiAlarm: Couldnt not set backround for screenlock"
		display dialog (localized string "ERROR_ScreenLock" from table "Localizable") buttons {"Ok"}
	end try
end SetLockImage

on SetAlertSounds()
	try
		set AlertMP3 to (content of default entry "AlertMP3" of user defaults)
		if AlertMP3 does not contain "none" then
			set alert_snd to load sound AlertMP3
		end if
	on error
		log "MultiAlarm: Could not set alert_snd"
		display dialog (localized string "ERROR_alertsnd" from table "Localizable") buttons {"Ok"}
		set alert_snd to load sound "lost.mp3"
	end try
	log "MultiAlarm: sound alert set to " & (content of default entry "AlertMP3" of user defaults)
end SetAlertSounds

on setalertvolume()
	
	try
		set AlertVolume to content of default entry "SoundAlertVolume" of user defaults
		log "MultiAlarm: Alert volume set to: " & AlertVolume
	on error
		log "MultiAlarm: Failed to set alert volume"
		display dialog (localized string "ERROR_alertvol" from table "Localizable") buttons {"Ok"}
	end try
end setalertvolume

on SetPass()
	try
		if passwordCheck("MultiAlarm") is equal to 1 then
			set thePass to quoted form of (getPW("MultiAlarm"))
			log "MultiAlarm: Password was retrived from keychain"
			--log thePass
		else
			log "MultiAlarm: Password is not set"
		end if
	on error
		log "MultiAlarm: Failed to retrive password"
		display dialog (localized string "ERROR_RetrivePass" from table "Localizable") buttons {"Ok"}
	end try
end SetPass

--Gets and organises coordinates
on getXY(theCoords)
	set oldTID to AppleScript's text item delimiters
	set text item delimiters to {" "}
	set theX to first text item of theCoords
	set theY to second text item of theCoords
	set text item delimiters to oldTID
	return {theX, theY}
end getXY

--Checks if password item exists in keychain
on passwordCheck(KeyName)
	try
		getPW(KeyName)
		return 1
	on error
		return 0
	end try
end passwordCheck

--gets machine name
on getSystem(theMachine)
	set oldTID to AppleScript's text item delimiters
	set text item delimiters to {"        "}
	set theName to first text item of theMachine
	set text item delimiters to oldTID
	return {theName}
end getSystem


--SETS THE PASSWORD
on setPassword(newPWD, KeyName)
	
	tell application "Keychain Scripting"
		-- look up our key
		try
			set myStoogeKey to first generic key of current keychain whose service is KeyName
		on error
			set myStoogeKey to ""
		end try
		-- if we found our key, delete it
		if (myStoogeKey is not "") then
			delete myStoogeKey
		end if
		
		-- make a new key
		make new generic key with properties {name:KeyName, account:KeyName, service:KeyName, password:newPWD}
		set myStoogeKey to the result
		
	end tell
end setPassword

--GETS KEYCHAIN PASSWORD
on getPW(KeyName)
	tell application "Keychain Scripting"
		launch
		tell current keychain to tell (some generic key whose name is KeyName) to set PWD to password
	end tell
	return PWD
end getPW

--Checks and controls growl
on GrowlNotify(myName, myTitle, myText)
	set myApp to ""
	tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
	if GrowlRunning ≥ 1 then
		try
			set myApp to "GrowlHelperApp"
			set notifs to "{\"Alarm Activated\", \"Alarm Deactivated\",\"Theft in progress\"}"
			tell application myApp to run script "register as application \"" & appName & "\" all notifications " & notifs & " default notifications " & notifs & " icon of application \"" & appName & "\""
			tell application myApp to run script "notify with name \"" & myName & "\" title \"" & myTitle & "\" application name \"" & appName & "\" description \"" & myText & "\" icon of application \"" & appName & "\""
		end try
	end if
end GrowlNotify

on iSightCall()
	try
		set isightcmd to do shell script thisHere & "Contents/Resources/isightcapture -d  -w 640 -h 480 " & thisHere & "Contents/Resources/isight.jpg"
		log "MultiAlarm: iSightCapture saved to " & thisHere & "Contents/Resources/isight.jpg"
	on error
		log "MultiAlarm: iSightcapture failed"
	end try
	if (content of default entry "iSightLocalCopy" of user defaults) is true then
		try
			set isightsavepath to (content of default entry "iSightSave" of user defaults)
			log "MultiAlarm: Trying to copy to - " & isightsavepath
			log "cp " & thisHere & "Contents/Resources/isight.jpg" & " " & isightsavepath
			do shell script "cp " & thisHere & "Contents/Resources/isight.jpg" & " " & isightsavepath
			log "MultiAlarm: Manual save location completed"
		on error
			log "MultiAlarm: Could not copy iSight image"
		end try
	end if
	if (content of default entry "iSightiDiskCopy" of user defaults) is true then
		try
			do shell script "cp " & thisHere & "Contents/Resources/isight.jpg" & " " & "/Volumes/iDisk"
			log "MultiAlarm: iDisk Copy Saved"
		on error
			log "MultiAlarm: Could not copy iSight image"
		end try
	end if
	if (content of default entry "FTP" of user defaults) is true then
		log "MultiAlarm: Starting FTP Upload"
		try
			do shell script "curl -T " & thisHere & "Contents/Resources/isight.jpg -u " & (content of default entry "FTPUser" of user defaults) & ":" & (content of default entry "FTPPass" of user defaults) & " " & (content of default entry "FTPSite" of user defaults) & (content of default entry "FTPDir" of user defaults) & "> /dev/null 2>&1 &"
			log "MultiAlarm: FTP Upload Finished"
		on error
			log "MultiAlarm: FTP Upload failed"
		end try
	end if
end iSightCall

on alertEmail(do)
	try
		do shell script ("echo " & (content of default entry "emailAlertMsg" of user defaults) & " | " & "sendmail " & (content of default entry "emailAlertAddress" of user defaults))
		--set alarmtimestamp to quoted form of ("Alarm Activation at " & (do shell script "date"))
		--do shell script ("echo " & (content of default entry "emailAlertMsg" of user defaults) & " | " & "mail -s " & alarmtimestamp & " " & (content of default entry "emailAlertAddress" of user defaults))
	on error
		log "MultiAlarm: Could not send alert email"
		display dialog (localized string "ERROR_AlertEmail" from table "Localizable") buttons {"Ok"}
	end try
end alertEmail

--Controls what happens when alarm is set off
on alarmAlert(do)
	if (content of default entry "AlertMP3" of user defaults) is not equal to "None" then
		try
			--tell application "iTunes" to pause
			set AlertVolume to content of default entry "SoundAlertVolume" of user defaults
			set volume AlertVolume
		on error
			log "MultiAlarm: Failed to set alert volume"
			display dialog (localized string "ERROR_alertvol" from table "Localizable") buttons {"Ok"}
		end try
		--Play alarm sound
		play alert_snd
	end if
end alarmAlert

--Controls what happens when alarm is told to lock
on activateLock(do)
	set LogFile to quoted form of (thisHere & "Contents/Resources/log.txt")
	tell user defaults to set content of default entry "state" to "armed"
	set my_command to thisHere & "Contents/Resources/screenlock.app/Contents/MacOS/screenlock -pic " & picPath & " -pass " & thePass & " -max " & (content of default entry "MaxAttempts" of user defaults) & " -timer " & (content of default entry "AlertDelay" of user defaults) & " -blocked " & (content of default entry "BlockTime" of user defaults) & " -log " & LogFile & " -key disarmed"
	do shell script my_command & "> /dev/null 2>&1 &"
	log "MultiAlarm : Starting Screen-Lock"
	--pause 2
end activateLock
--------------------Insomnia Functions----------------------
on LoadInsomnia()
	try
		do shell script "chown -R root:wheel " & thisHere & "Contents/Resources/" & "Insomnia.kext" user name myName password AdminKey with administrator privileges
		do shell script "kextload " & thisHere & "Contents/Resources/" & "Insomnia.kext" user name myName password AdminKey with administrator privileges
	on error
		log "MultiAlarm: Insomnia was not loaded"
		display dialog (localized string "ERROR_LoadInsomnia" from table "Localizable") buttons {"Ok"}
	end try
end LoadInsomnia

on UnLoadInsomnia()
	try
		do shell script "kextunload " & thisHere & "Contents/Resources/" & "Insomnia.kext" user name myName password AdminKey with administrator privileges
	on error
		display dialog (localized string "ERROR_UnLoadInsomnia" from table "Localizable") buttons {"Ok"}
	end try
end UnLoadInsomnia


---------------------Alarm Functions---------------------

--Alarm Activation Script
on alarmActivate(do)
	--if (content of default entry "motionEngine" of user defaults) does not contain "Disable" or UseNonSMS is true then
	if (content of default entry "UniMotion" of user defaults) is true or (content of default entry "UseNonSMS" of user defaults) is true then
		
		tell user defaults to set content of default entry "state" to "armed"
		--Checks if should activate screenlock on arm
		if (content of default entry "preLock" of user defaults) is true then
			activateLock(1)
		end if
		set theOldVolume to get output volume of (get volume settings)
		--if UseSMS is true and (content of default entry "motionEngine" of user defaults) does not contain "Disable" then
		if UseSMS is true and (content of default entry "UniMotion" of user defaults) is true then
			--runs motion cmd to find x and y axis
			try
				set motionEngine to thisHere & "Contents/Resources/UniMotion"
				set theCoords to do shell script motionEngine
				if theCoords is not "" then
					set {theX, theY} to getXY(theCoords)
					set theX to theX + 1000
					set theY to theY + 1000
					set theUpperX to theX + (content of default entry "alarmSensitivity" of user defaults)
					set theLowerX to theX - (content of default entry "alarmSensitivity" of user defaults)
					set theUpperY to theY + (content of default entry "alarmSensitivity" of user defaults)
					set theLowerY to theY - (content of default entry "alarmSensitivity" of user defaults)
				end if
			on error
				display dialog (localized string "ERROR_UniMotion" from table "Localizable") buttons {"Ok"}
			end try
		end if
		if (content of default entry "ArmSound" of user defaults) is true then
			play theArming
		end if
		--Gets admin key
		if UseSMS is true and (content of default entry "SleepControl" of user defaults) is true then
			if passwordCheck("AdminKey") is equal to 1 then
				try
					set AdminKey to getPW("AdminKey")
					log "MultiAlarm: AdminKey retrived"
				on error
					log "MultiAlarm: AdminKey Could not be retrived"
					display dialog (localized string "ERROR_AdminAuth" from table "Localizable") buttons {"Ok"}
				end try
			else
				display dialog (localized string "ERROR_AdminAuth" from table "Localizable") buttons {"Ok"}
			end if
		end if
		if UseSMS is true and (content of default entry "SleepControl" of user defaults) is true then
			LoadInsomnia()
		end if
		set alarmActivated to true
		changeStatus("armed.png")
		GrowlNotify("Alarm Activated", "Alarm", "Warning : Alarm Primed")
	else
		display dialog (localized string "ERROR_NoAlarm" from table "Localizable") buttons {"Ok"}
	end if
end alarmActivate

--Alarm Deactivation Script
on alarmDeactivate(do)
	
	if (content of default entry "AlertMP3" of user defaults) does not contain "None" then
		stop alert_snd
	end if
	if UseSMS is true and (content of default entry "SleepControl" of user defaults) is true then
		UnLoadInsomnia()
	end if
	--Deactivates the check
	set alarmLocked to false
	set alarmActivated to false
	set volume output volume theOldVolume
	--play (load sound "arm.wav")
	if (content of default entry "DisarmSound" of user defaults) is true then
		play theArming
	end if
	--Displays growl notification
	changeStatus("disarmed.png")
	GrowlNotify("Alarm Deactivated", "Alarm", "Warning : Alarm Disarmed")
end alarmDeactivate

--Code executed for alerts
on alarmactivation()
	(*if (content of default entry "AlertDelay" of user defaults) is not equal to 0 then
		log "MultiAlarm: Delaying alert for " & (content of default entry "AlertDelay" of user defaults)
		pause (content of default entry "AlertDelay" of user defaults)
	end if*)
	
	--alarmAlert(1)
	GrowlNotify("Theft in progress", "Alarm", "Warning : Theft in progress")
	if (content of default entry "iSight" of user defaults) is true then
		log "MultiAlarm: Calling iSight camera"
		iSightCall()
	end if
	--Email Alert
	if (content of default entry "emailAlert" of user defaults) is true then
		alertEmail(1)
		log "MultiAlarm : Alarm sent email"
	end if
	
	--Script Alert
	if (content of default entry "EnableAlertScript" of user defaults) is true then
		try
			set alertScript to (content of default entry "alertScript" of user defaults) as alias
			run script alertScript
		on error
			display dialog (localized string "ERROR_AlertScript" from table "Localizable") buttons {"Ok"}
		end try
	end if
end alarmactivation

Check out the documentation for [url=http://developer.apple.com/documentation/AppleScript/Reference/StudioReference/sr3_app_suite/sr_app.html#//apple_ref/doc/uid/20011217-ASKApplicationSuite.Classes.ASKDefaultEntry]default entry[/url]:

Also, check this thread: Convert Unicode Text to Plain Text (or Boolean)

Well its seems abnormal having to do such a thing for one and only one in the whole application, but ill try it anyway.

(Since OS X v10.3, display dialog returns Unicode text.)

Examples:

display dialog "Unicode coerced to boolean test:" default answer "true"
(text returned of result) is true
--> false

display dialog "Unicode coerced to boolean test:" default answer "true"
(text returned of result as boolean) is true
--> Coercion error

display dialog "Unicode coerced to boolean test:" default answer "true"
set {text:convertedAnswer} to (text returned of result as string)
convertedAnswer is true
--> false

display dialog "Unicode coerced to boolean test:" default answer "true"
set {text:convertedAnswer} to (text returned of result as string)
(convertedAnswer as boolean) is true
--> true

display dialog "Unicode coerced to boolean test:" default answer "true"
(text returned of result) is "true"
--> true