10.0.3 has stuffed up System Preferences Pane open/closed

G’day scripters

The update to Yosemite 10.0.3 has stuffed up the ability to tell whether a System Preferences Pane is open or not.

A handler portion I rely heavily on now returns a constant ˜true’ when run, when testing for the visiblilty of ˜com.apple.preference.security’, and to add to that, the handler opens up the ˜System Preferences’ window when opening the Pane on a second pass when the answer should be ˜false’.

I’ve tried getting the visible of the Pane, but that didn’t work.

Does any one know of an alternative method of determine if the Pane is visible or not, please?

Regards

Santa


tell application "System Preferences"
				activate
				tell pane id "com.apple.preference.security" to reveal anchor "Privacy_Accessibility"
				try
					repeat while exists pane id "com.apple.preference.security" ”< THIS NEVER QUITS NOW
						tell current application to delay 0.1
						if (current date) - (my theStartTime) > 40 then
							set displayDialogAD to displayDialogADSecond
							fieldAssistiveAccessAdvice's setStringValue:(displayDialogAD)
							fieldAssistiveAccessAdvice's display()
							tell current application's NSColorList to set AppleColors to colorListNamed_("Apple")
							set someColor to AppleColors's colorWithKey:"Red"
							fieldAssistiveAccessAdvice's setTextColor:someColor
							fieldAssistiveAccessAdvice's display()
							set my theStartTime to ((current date) - 30)
							activate
						end if
					end repeat
				end try
			end tell

Here’s a test script.


tell application "System Preferences"
	activate
	tell pane id "com.apple.preference.security" to reveal anchor "Privacy_Accessibility"
	repeat while exists pane id "com.apple.preference.security" --< QUIT WITH THE RED CLOSE BUTTON, THIS NEVER QUITS NOW
		say (exists pane id "com.apple.preference.security")
		delay 4
	end repeat
end tell

Hi Santa,

I haven’t tried your script.

Maybe it’s a new security thing?

Maybe you need to add delays?

Don’t know.

gl,
kel

Oh wait, you didn’t add the frameworks or do you need to do that?

Edited: interesting. I need to learn this stuff also.

G’day Kel

The method I posted is a small part of a whole ASOBJC routine I use to determine if an application is restricted in it’s assistive access.

Here’s the whole routine, with three handlers, with a workaround for the problem that I just came up with. If you want more details, post here.

I’ve posted a bug error, 20511595

Regards

Santa


	on initializingRoutineTwo()
		set tryLoops to 0
		repeat
			try
				set my assistTrial to true
				set tryLoops to tryLoops + 1
				repeat
					tell application "Finder"
						set TextEditExists to exists process "TextEdit"
					end tell
					if TextEditExists then
						set x to 0
						try
							tell application "TextEdit"
								repeat while exists document 1
									try
										close document 1 without saving
									end try
									set x to x + 1
									tell current application to delay 0.1
									if x = 20 then exit repeat
								end repeat
								# tell current application to delay 0.4
								try
									quit
								end try
							end tell
						end try
					else
						exit repeat
					end if
				end repeat
				tell application "TextEdit"
					repeat
						activate
						try
							tell current application to delay 0.1
							tell application "System Events" to tell process "TextEdit"
								try
									repeat until (exists menu item "New" of menu 1 of menu bar item "File" of menu bar 1)
										tell current application to delay 0.1
									end repeat
									click menu item "New" of menu 1 of menu bar item "File" of menu bar 1
									exit repeat
								on error errmsg number errnum
									if errnum = -1719 or errnum = -25211 then
										set my assistTrial to false
										exit repeat
									end if
								end try
							end tell
						on error errmsg number errnum
							tell application "System Events" to display dialog "Text Edit Start error " & errmsg & " number " & errnum giving up after 20
							set my assistTrial to false
						end try
					end repeat
					tell current application to delay 0.2
					try
						set x to 0
						tell application "TextEdit"
							repeat while exists document 1
								try
									close document 1 without saving
								end try
								tell current application to delay 0.1
								set x to x + 1
								if x = 20 then exit repeat
							end repeat
						end tell
					end try
					try
						quit
					end try
				end tell
			on error errmsg number errnum
				try
					tell application "TextEdit" to quit
				end try
				tell application "System Events" to display dialog "initializingRoutineTwo - set up Assistive Devices test " & errmsg & " error number " & errnum giving up after 20
			end try
			if not my assistTrial then
				my turnOnAssistiveDevices()
				set my theAssistFlag to (my theAssistFlag) + 1
			else
				exit repeat
			end if
		end repeat
		windowAssistiveAccess's orderOut:me
		
                my setUp() # OR WHATEVER
	
         end initializingRoutineTwo
	
 on turnOnAssistiveDevices()
		try
			windowAssistiveAccess's makeKeyAndOrderFront:me
			tell windowAssistiveAccess to displayIfNeeded()
			# deliberately create error
			try
				# commenting out the next line will stop the window showing
				# errorStatement MUST NOT  be declared as a property
				set my errorStatement to true
			on error
				tell me to activate
				display dialog "Opening Assistive Settings" giving up after 1
			end try
			my turnOnAssistiveDevicesSecond()
		on error errmsg
			tell application "System Events" to display dialog "turnOnAssistiveDevices error " & errmsg & return & "p = " & p
		end try
	end turnOnAssistiveDevices
	
	on turnOnAssistiveDevicesSecond()
		try
			set p to 1
			set my theStartTime to current date
			set p to 2
			set theTimes to "once."
			set p to 3
			if my theAssistFlag = 2 then set theTimes to "twice." as text
			set p to 4
			if my theAssistFlag > 2 then set theTimes to my theAssistFlag & " times." as text
			set p to 5
			set insertedText to "then please unlock the pane using the lower left padlock, and entering this Macs sign on password, then (but first untick if already ticked), tick the adjoining tick box to the 'Mail Manager Item Printer' icon, or, click the '+' sign and navigate to 'Mail Manager Item Printer', then select it, and drag it to the accessibility window and tick its tick box." & return & return & "NOTE that you must close  the 'Security & Privacy' window before Mail Manager Item Printer will resume." as text
			set p to 6
			set displayDialogAD to "You need to set 'Accessibility for Assistive Devices' for" & return & return & "Mail Manager Item Printer." & return & return & "I'll open up the 'Security & Privacy' system preferences pane, " & insertedText
			set p to 7
			if my theAssistFlag > 0 then
				set p to 8
				set displayDialogAD to "You have already tried to set 'Security & Privacy' " & theTimes & return & return & "I'll open up the 'Security & Privacy' system preferences pane again, " & insertedText as text
				set p to 9
				if my theAssistFlag > 3 then
					set p to 10
					set theText to paragraph 1 of displayDialogAD as text
					my sayTheText(theText) --< Works OK!
				end if
			end if
			set p to 11
			set displayDialogADSecond to "YOU ARE TAKING A LONG TIME TO SET" & return & "the 'Security & Privacy' pane." & return & return & "If you haven't already unlocked the pane, " & insertedText as text # activate me
			set p to 12
			windowAssistiveAccess's makeKeyAndOrderFront:me
			set p to 13
			fieldAssistiveAccessAdvice's setStringValue:(displayDialogAD)
			set p to 14
			fieldAssistiveAccessAdvice's display()
			tell application "Finder"
				try
					set p to 15
					set pathToContainerOfMe to container of (path to current application) as text
					set p to 16
					open folder pathToContainerOfMe
				end try
			end tell
			set p to 17
			tell application "System Preferences"
				activate
				set p to 18
				repeat
					tell pane id "com.apple.preference.security" to reveal anchor "Privacy_Accessibility"
					# tell current application to delay 2
					set p to 19
					tell current application to delay 0.1
					try
						set p to 20
						if (current date) - (my theStartTime) > 40 then
							set p to 21
							set displayDialogAD to displayDialogADSecond
							set p to 22
							fieldAssistiveAccessAdvice's setStringValue:(displayDialogAD)
							set p to 23
							fieldAssistiveAccessAdvice's display()
							set p to 24
							tell current application's NSColorList to set AppleColors to colorListNamed_("Apple")
							set p to 25
							set someColor to AppleColors's colorWithKey:"Red"
							set p to 26
							fieldAssistiveAccessAdvice's setTextColor:someColor
							set p to 27
							fieldAssistiveAccessAdvice's display()
							set p to 28
							set my theStartTime to ((current date) - 30)
							# activate
						end if
						set p to 29
						tell application "System Events" to tell process "System Preferences"
							tell current application to delay 0.1
							set p to 30
							tell application "System Events" to tell process "System Preferences"
								set p to 31
								if not (exists window "Security & Privacy") then
									set p to 32
									exit repeat
								end if
							end tell
						end tell
					on error errmsg number errnum
						if p = 31 and errnum ≠ -25211 then
							tell application "System Events" to display dialog errmsg & return & "number " & errnum & " p = " & p giving up after 40
						else
							tell current application to delay 1
						end if
					end try
				end repeat
			end tell
		on error errmsg number errnum
			tell application "System Events" to display dialog "Mail Manager Item Printer  turnOnAssistiveDevices " & errmsg & " p = " & p as text giving up after 40
		end try
		try
			windowAssistiveAccess's orderOut:me
		on error errmsg number errnum
			tell application "System Events" to display dialog "Mail Manager Item Printer turnOnAssistiveDevices second " & errmsg & " number " & errnum & " p = " & p as text giving up after 40
		end try
	end turnOnAssistiveDevicesSecond
	

Hi,

What I was saying, but don’t know about is that don’t you need to add the frameworks at the beginning like:

If you want to use the Objective C stuff. I’m quite sure it’s not built into AppleScript.

gl,
kel

Why not


tell application "System Preferences"
	activate
	tell pane id "com.apple.preference.security" to reveal anchor "Privacy_Accessibility"
	repeat while it is running
		say (exists pane id "com.apple.preference.security")
		delay 4
	end repeat
end tell

G’day Stefan, and thanks for trying.

However, on my machine, the loop in your method continues with ‘true’ even when the red close button on the System Preferences window is clicked, and the window closes.

With 10.0.3 Apple seems to have introduced a feature that ‘sees’ a Pane as existing even when it’s not open.

The code I posted, that relies on constantly trapping the resultant error, works, but I dislike using error trapping.

Regards

Santa


                                 repeat
					tell pane id "com.apple.preference.security" to reveal anchor "Privacy_Accessibility"
					# tell current application to delay 2
					set p to 19
					tell current application to delay 0.1
					try
						set p to 20
						if (current date) - (my theStartTime) > 40 then
							set p to 21
							set displayDialogAD to displayDialogADSecond
							set p to 22
							fieldAssistiveAccessAdvice's setStringValue:(displayDialogAD)
							set p to 23
							fieldAssistiveAccessAdvice's display()
							set p to 24
							tell current application's NSColorList to set AppleColors to colorListNamed_("Apple")
							set p to 25
							set someColor to AppleColors's colorWithKey:"Red"
							set p to 26
							fieldAssistiveAccessAdvice's setTextColor:someColor
							set p to 27
							fieldAssistiveAccessAdvice's display()
							set p to 28
							set my theStartTime to ((current date) - 30)
							# activate
						end if
						set p to 29
						tell application "System Events" to tell process "System Preferences"
							tell current application to delay 0.1
							set p to 30
							tell application "System Events" to tell process "System Preferences"
								set p to 31
								if not (exists window "Security & Privacy") then
									set p to 32
									exit repeat
								end if
							end tell
						end tell
					on error errmsg number errnum
						if p = 31 and errnum ≠ -25211 then
							tell application "System Events" to display dialog errmsg & return & "number " & errnum & " p = " & p giving up after 40
						else
							tell current application to delay 1
						end if
					end try
				end repeat

Kel, if you’re referring to my initializng the script, This is it…


script AppDelegate
	property parent : class "NSObject"
	
	use AppleScript version "2.4"
	use framework "Foundation"
	use framework "AppKit"
	use scripting additions
	
	property windowAssistiveAccess : missing value
	property fieldAssistiveAccessAdvice : missing value
	
	property theStartTime : current date
	property theAssistFlag : 0
	property assistTrial : false
	

On my machine (also 10.0.3) it’s working.
Clicking on the red button is supposed to cause System Preferences to quit.

Hi Santa.

Stefan’s version of the test script works for me.

The problem with your original is that the repeat keeps sending commands to System Preferences, causing it to launch again in the background. And all its panes exist while it’s open, even when they’re not revealed:

tell application "System Preferences"
	launch
	return panes
end tell

By the way, the colour of the “red” button depends on the setting in another System Preferences pane. :slight_smile:

G’day Nigel, and again to Stefan.

Thanks for the explanation Nigel. Seems obvious once pointed out.

My script is now…

Regards

Santa


tell application "Finder"
				try
					set p to 15
					set pathToContainerOfMe to container of (path to current application) as text
					set p to 16
					open folder pathToContainerOfMe
				end try
			end tell
			set p to 17
			tell application "System Preferences"
				activate
				set p to 18
				tell pane id "com.apple.preference.security" to reveal anchor "Privacy_Accessibility"
	      			repeat while it is running
					tell application "System Events"
						delay 0.1
					 		set p to 20
							if (current date) - (my theStartTime) > 40 then
								set p to 21
								set displayDialogAD to displayDialogADSecond
								set p to 22
								fieldAssistiveAccessAdvice's setStringValue:(displayDialogAD)
								set p to 23
								fieldAssistiveAccessAdvice's display()
								set p to 24
								tell current application's NSColorList to set AppleColors to colorListNamed_("Apple")
								set p to 25
								set someColor to AppleColors's colorWithKey:"Red"
								set p to 26
								fieldAssistiveAccessAdvice's setTextColor:someColor
								set p to 27
								fieldAssistiveAccessAdvice's display()
								set p to 28
								set my theStartTime to ((current date) - 30)
								# activate
							end if
							set p to 29
					 end tell
				end repeat
			end tell