Toggle mouse left/right-hand layout

Didn’t find a solution here, but some pointers. Here’s my solution - for OS 10.6.x only - in case it helps others.

on run
	tell application "System Preferences"
		reveal pane "Mouse"
		tell application "System Events"
			tell process "System Preferences"
				tell window "Mouse"
					tell group 1
						tell pop up button 1
							delay 0.1
							keystroke (ASCII character 31) -- set left-handed
							keystroke return
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
	display dialog "mouse set for left-handed" giving up after 1 buttons {"OK"}
end run

This was then saved as a run-only app. The right-hand version is the same except for the final caption and “keystroke (ASCII character 30) – set right-handed” in the middle part.

Issues discovered resolved in making this:

  • Although you can get the value of the “pop-up button 1” you can’t set it. Thus the keystroke inputs, etc.
  • After experimentation and research I got the impression that ‘keystroke (ASCII character 31)’ was better than my original 'keystroke “down arrow” ’ input code.
  • The down arrow key version needs a delay, the up-arrow works without (go figure!). Originally I used a 1 second delay for both but 0.1 seems to work and makes the script seem less laggy. Anyway, without adding a delay, the right->left script hangs with an open pop-up list for no obvious reason.
  • The ‘on run / end’ enclosure was added after script based testing as the final code (above) was then saved as a pair (left/right) of run-only applets and placed in the user scripts folder being made available via the Mac menu bar (in 10.6.x enable this menu via Script Editor’s preferences). To get the correct layout the user just pops the scripts meny and clicks a non-techie title like “Fred’s mouse” or “Mary’s mouse”)
  • The closing dialog isn’t strictly necessary but is there for the less-tech-aware of the users who feel more confident a change has occurred if they get feedback.

Very happy to receive suggestions to improvements (or errors) but if nothing else I hope this saves others the time needed to figure such a script - necessary with left/right handed folk using the same user account! (Separate accounts don’t help when the ‘sharing’ is giving tech support to one’s partner, IOW activity has to be in the same account).

Model: iMac 27"
AppleScript: 2.1.1
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

This script doesn’t seem to work under OS X 10.7. Any idea how to fix it?

Sorry, I’'m afraid not as I can’t move to Lion yet (have to wait for key work apps to be compatible). I’m still on 10.6.8 for now.

Someone else perhaps?

Model: MBPro, early 2011
Browser: Safari 534.51.22
Operating System: Mac OS X (10.6)