Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mactp

macrumors newbie
Original poster
Mar 13, 2014
13
1
I have the AppleScript to toggle the "Ignore built-in trackpad when mouse is present" preference on OSX Mavericks working in the code box below, but I can't keep the "System Preferences" hidden and get the annoying flash as it activates the application window briefly to turn the trackpad on or off. Any thoughts on how I might hide this process? More details below...

Code:
-- open trackpad preferences
tell application "System Preferences"
	activate
	reveal (pane id "com.apple.preference.universalaccess")
end tell

tell application "System Events"
	tell process "System Preferences"
		tell window "Accessibility"
			tell scroll area 1
				click UI element "Mouse & Trackpad" of row 10 of table 1
			end tell
			
			-- click trackpad enable/disable when connected
			tell checkbox 2
				click
			end tell
			
			click button "Show All" of group 1 of group 2 of toolbar 1
		end tell
	end tell
end tell

tell application "System Preferences"
	quit
end tell

Some background: I use my Macbook Pro with Mavericks both with and without an external mouse (a Logitech trackball actually). Both because I hate stray trackpad input as I type and because using only the trackpad can cause me wrist pain after a while, I like to set the "System Preferences / Accessibility / Mouse & Trackpad / Ignore built-in trackpad when mouse or wireless trackpad is present" checkbox to true when using the USB trackball.

But because I also like to leave the tiny USB dongle in there, when I don't bother to bring the trackball along I can't easily use the built-in trackpad. So I have been writing an AppleScript to tell System Preferences toggle the Ignore Trackpad setting. That way I can just use command-space to start spotlight and run the ToggleTrackpad script from the keyboard.

I am open to other solutions to this problem. I looked into finding a defaults write command for this by seeing if any plist files changed in the ~/Library/Preferences directory, but nothing seemed to change when I ran a diff on their old versions, so I never could figure out where in Mavericks this setting was being stored.
 
Last edited:
I am open to other solutions to this problem. I looked into finding a defaults write command for this by seeing if any plist files changed in the ~/Library/Preferences directory, but nothing seemed to change when I ran a diff on their old versions, so I never could figure out where in Mavericks this setting was being stored.

Perhaps this is what you're looking for?
 

Attachments

  • Picture 1.png
    Picture 1.png
    152.7 KB · Views: 280
No luck

Perhaps this is what you're looking for?

I tried to use

Code:
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad USBMouseStopsTrackpad 1

and while it changes the value successfully, no effect.

And when the value is changed using the GUI's System preferences Accessiblity Mouse Ignore... the value in that plist does not change.

So that's not it, though it was a good suggestion.
 
Try changing this:
Code:
tell application "System Events"
	tell process "System Preferences"
to this:
Code:
tell application "System Events"
	set visible of process "System Preferences" to false
	tell process "System Preferences"
I don't know if making the process invisible will cause the subsequent UI Scripting to fail. It's a simple one-line addition. Try it, see what happens.

There will still be an initial flash as System Preferences activates. Try changing the initial activate command to launch. Refer to the AppleScript Language Guide, and look at the launch command.
https://developer.apple.com/library...applescriptlangguide/reference/aslr_cmds.html


Google search terms:
applescript launch hidden

One of the top results:
https://discussions.apple.com/thread/2193128
 
I'm grasping at straws here but maybe it has something to do with preference caching in Mavericks. There's some interesting stuff to read here
 
Try changing this:
Code:
tell application "System Events"
	tell process "System Preferences"
to this:
Code:
tell application "System Events"
	set visible of process "System Preferences" to false
	tell process "System Preferences"
I don't know if making the process invisible will cause the subsequent UI Scripting to fail. It's a simple one-line addition. Try it, see what happens.

There will still be an initial flash as System Preferences activates. Try changing the initial activate command to launch. Refer to the AppleScript Language Guide, and look at the launch command.
https://developer.apple.com/library...applescriptlangguide/reference/aslr_cmds.html


Google search terms:
applescript launch hidden

One of the top results:
https://discussions.apple.com/thread/2193128

Thanks. It did cause an error, presumably because of how I am scripting to the UI. Nor did launch make any difference. Interestingly removing the activate command works and appears to run hidden. I have updated the code with a try on error structure to activate only if it fails. The following seems to have removed the flash for now.

Code:
-- open trackpad preferences
tell application "System Preferences"
	try
		reveal (pane id "com.apple.preference.universalaccess")
		tell application "System Events"
			tell process "System Preferences"
				tell window "Accessibility"
					tell scroll area 1
						click UI element "Mouse & Trackpad" of row 10 of table 1
					end tell
					
					-- click trackpad enable/disable when connected
					tell checkbox 2
						click
					end tell
					
					click button "Show All" of group 1 of group 2 of toolbar 1
				end tell
			end tell
		end tell
	on error
		activate
		reveal (pane id "com.apple.preference.universalaccess")
		tell application "System Events"
			tell process "System Preferences"
				tell window "Accessibility"
					tell scroll area 1
						click UI element "Mouse & Trackpad" of row 10 of table 1
					end tell
					
					-- click trackpad enable/disable when connected
					tell checkbox 2
						click
					end tell
					
					click button "Show All" of group 1 of group 2 of toolbar 1
				end tell
			end tell
		end tell
	end try
	quit
end tell
 
Last edited:
I'm grasping at straws here but maybe it has something to do with preference caching in Mavericks. There's some interesting stuff to read here

Possibly. But I am using default write, and from those articles that is supposed to be cache proof. I also tried logging out and back in with the trackpad disabled to check the cache hypothesis, and it made no difference to the values in thsoe plist files.

Thanks for the suggestion. It would be nice to have found the defaults command to run from terminal, but I have now made the applescript work without flashing the System Preferences app into the foreground.

----------

I have also found another kludgey solution: Using CONTROL-F2 will allow one to use the keyboard to navigate the menus, and using the arrow keys to select system preferences, the spacebar to select, and the tab once I am finally into Universal Access, I can with about 30 keypresses manage to use GUI from the keyboard to re-enable the trackpad.

(Yeah, that's way too many keypresses, but the CTRL-F2 trick also seems to be handy for keyboard-oriented folks in general.) Note also that this could be FN-CTRL-F2 depending on your keyboard function key preference settings.
 
Last edited:
Code:
tell application "System Preferences" to [B]run[/B]

launches System Preferences and makes it available for UI scripting without making the app visible.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.