Mavericks Broke This Simple UI Script

This used to work flawlessly:

tell application “System Preferences”
activate
end tell

delay 1

tell application “System Events”
activate
click menu item “Mouse” of menu “View” of menu bar 1 of process “System Preferences”
end tell

Now, It just launches System Preferences and sits there. I have authorized the app multiple times. If I leave System Prefs open and run the script a second time, it will sometimes work. Why won’t it just work on the first try since I won’t be here to run it a second time?

Hello

Here is an edited version which seems to work flawlessly with localized versions :

activate application "System Preferences"
set app_loc to localized string "CFBundleName" from table "InfoPlist" in bundle file ((path to applications folder from local domain as text) & "System Preferences.app")
set mouse_loc to localized string "CFBundleName" from table "InfoPlist" in bundle file ((path to library folder from system domain as text) & "PreferencePanes:Mouse.prefPane:")

tell application "System Events"
	set frontmost of process "System Preferences" to true
	# Loop waiting for System Preferences menu
	repeat 50 times
		delay 0.1
		name of (menu 2 of menu bar 1 of (first process whose frontmost is true))
		if result is app_loc then exit repeat
	end repeat
	
	tell process "System Preferences" to tell menu 4 of menu bar 1
		# Loop waiting for the complete menu
		repeat
			delay 0.1
			click it
			if (count menu items) > 10 then exit repeat
		end repeat
		click menu item (mouse_loc as text)
	end tell
end tell

This said, maybe this alternate one would be more efficient :

-- Open the Mouse PrefPane
do shell script "/usr/bin/open /System/Library/PreferencePanes/Mouse.prefPane"

Yvan KOENIG (VALLAURIS, France) jeudi 6 février 2014 16:54:09

The short version works perfectly. Thanks!