Toggling UI elements in Mavericks

In Mavericks the code below fails:

tell application "System Events"
	set testApp to "TextEdit.app"
	if not (application process testApp exists) then tell application process testApp to activate
	log (UI elements enabled) as boolean -- Events logged: (*false*)
	try
		set (UI elements enabled) to not (UI elements enabled)
	on error e
		return e
	end try
end tell
-- result returned: "System Events got an error: Can't set UI elements enabled of application to true."

Does anybody know how to modify the code below so that it adds the current application to the allowed apps list (checked on) of Security & Privacy prefPane?
It will surely have to be done by entering an admin password but that’s ok for my purpose.
Thanks.

-- for the login items this code works
try
	tell application "System Events"
		set myPath to (path to current application)
		set myName to (name of current application)
		log "myName is in (name of every login item) returns: " & (myName is in (name of every login item)) as text -- (*myName is in (name of every login item) returns: false*)
		if myName is not in (name of every login item) then
			make new login item at end of login items with properties {name:myName, kind:"APPLICATION", path:myPath, hidden:true}
		end if
		log "myName is in (name of every login item) returns: " & (myName is in (name of every login item)) as text -- (*myName is in (name of every login item) returns: true*)
		if (myName is in (name of every login item)) then
			display dialog "Success" with icon 1 buttons {"OK"} default button 1
		end if
	end tell
on error myErr
	log myErr
	display dialog "Failed to add to login items, you'll have to do it manually." with icon 1 buttons {"OK"} default button 1
end try

See this thread, I think it will solve your problem http://macscripter.net/viewtopic.php?id=41625

Model: Mac Pro 6,1
AppleScript: 2.6
Browser: Safari 537.73.11
Operating System: Mac OS X (10.8)

Hi Rich_Cohen,

Thanks for that.
I have considered this path before.
I would need to include the plist file with every app I distribute and then run the terminal command. I also would have to check each time I run that the user did not delete or move the plist.
I am not sure how this would work internationally and I cannot afford problem dialog boxes or my app failing (it is a faceless app).
I since found a way of working without UI Elements instead.