Menu bar color

Hello -

2 strange phenomenons

When starting up there is a four-liner consisting of pixels; this disappears then.

More interesting - the menubar shows the color of the desktop even when the 2nd monitor is not connected.
Then I have to de- and reactivate “Synchronize Monitors”
I wanted to use an Applescript as starting object and found this:


do shell script “open /System/Library/PreferencePanes/Displays.prefPane”
delay 2 --wenn Dein Rechner da langsamer ist… größerer Delay… I love GU
activate application “System Preferences”
tell application “System Events”
tell process “System Preferences”
if title of radio button 2 of tab group 1 of window 1 = “Anordnen” then
click radio button “Anordnen” of tab group 1 of window 1
click checkbox 1 of tab group 1 of window 1
else
display dialog “Falsche Sprache oder kein 2. Monitor”
end if
end tell
end tell
tell application “System Preferences” to quit

but it tells

žSystem Events" got a failure: žgroup 1 of tab group 1 of window 1 of process “System Preferences”" cannot be read. No valid Index.(*)

(*) Translated from German system.

Could a kind soul help and perhaps tell the core of the problem and a solution without workarounds?

Thank you in advance

Kind regards

Peter

AppleScript: 2.6.1
Browser: Safari 537.76.4
Operating System: Mac OS X (10.8)

Hi,

easier version to get the number of displays


tell application "System Events" to set numberOfDisplays to count desktops

easier version to open the 'Anordnen" tab of pane “Displays” of System Preferences,
regardless of the current language and no GUI scripting at all


tell application "System Preferences"
	activate
	reveal anchor "displaysArrangementTab" of pane id "com.apple.preference.displays"
end tell

so you can write


tell application "System Events" to set numberOfDisplays to count desktops
if (numberOfDisplays > 1) then
	tell application "System Preferences"
		activate
		reveal anchor "displaysArrangementTab" of pane id "com.apple.preference.displays"
	end tell
end if