Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.5: Set different modifier keys for external keyboards' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Set different modifier keys for external keyboards
Authored by: Anonymous on Dec 19, '07 11:24:01PM
It seems some external keyboards don't get recognized by Leopard, so the automatic modifier switching doesn't work for them. Yury Soldak emailed me yesterday, with a modified version of the above code which works with the Leopard (the drop-down indexes changed because of the extra button, and there's a few other changes) Here's the code - to swap the command and option keys on an external keyboard on Leopard: (Its an AppleScript, copy and paste it into Script Editor and save/run it)
tell application "System Preferences"
	activate
	set current pane to pane
	"com.apple.preference.keyboard"
end tell


tell application "System Events"
	-- If we don't have UI Elements enabled, then nothing is really going to work.
	if UI elements enabled then
		tell application process "System Preferences"
			get properties
			
			-- Open up the Modifier Keys sheet
			click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
			tell sheet 1 of window "Keyboard & Mouse"
				if pop up button 5 exists then
					-- looks like we have external keyboard.  Swap the keys for all
					click pop up button 5
					click menu item "All" of menu 1 of pop up button 5
					delay 1
					-- command key to alt
					click pop up button 1
					click menu item 3 of menu 1 of pop up button 1
					delay 1
					-- alt key to command
					click pop up button 2
					click menu item 4 of menu 1 of pop up button 2
					delay 1
					-- restore defaults for internal keyboard
					click pop up button 5
					click menu item "Apple Internal Keyboard / Trackpad" of menu 1 of pop up button 5
					delay 1
					click button "Restore Defaults"
				else
					click button "Restore Defaults"
				end if
				-- close the sheet
				click button "OK"
			end tell
		end tell
		tell application "System Preferences" to quit
	else
		-- UI elements not enabled.  Display an alert
		tell application "System Preferences"
			activate
			set current pane to pane "com.apple.preference.universalaccess"
			display dialog "UI element scripting is not enabled.
             Check \"Enable access for assistive devices\""
		end tell
	end if
end tell


[ Reply to This | # ]