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

pgiguere1

macrumors 68020
Original poster
May 28, 2009
2,167
1,200
Montreal, Canada
PHP:
Code:
Apple chose to force the toggle of scrolling direction for all pointing devices whenever you want to toggle only one of them in the Lion preferences. Many users including myself adopted the new default Natural scrolling for use with their Trackpad but can't get used to it when they scroll with a mouse and would rather have the old, non-inverted scrolling when it's the case.

So far, the only way to achieve this without going to System Preferences every time you switch between your Trackpad and mouse was to install Scroll Reverser, a free app that sits in your menu bar and offers you more settings than Lion's default preferences. Unfortunately, Scroll Reverser is very buggy and constantly temporarily switches between scrolling orientations for no apparent reason. I found it to be even more annoying than manually switching the direction in System Preferences.

Since there is still no perfect solution to achieve natural scrolling only with your Trackpad without going to System Preferences every time, I decided to make my own using AppleScript and MarcoPolo.

Here's a tutorial on how to do it.

Natural scrolling only with Trackpad


Step 1 : Enabling access for assistive devices


To let the AppleScripts toggle your System Preferences settings, you will first need to enable access for assistive devices.

To do so, go in System Preferences -> Universal Access and check "Enable access for assistive devices".
step1a.png
Step 2 : Creating the AppleScripts


You will need to save two AppleScripts: one to enable Natural scrolling, the other to disable it.

Open the AppleScript Editor application located in /Applications/Utilities. Paste the following code in it:
Code:
tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.trackpad"
end tell

tell application "System Events"
	tell application process "System Preferences"
		tell tab group 1 of window "Trackpad"
			click radio button 2
			if value of checkbox 1 is 1 then
				click checkbox 1
			end if
		end tell
	end tell
end tell

tell application "System Preferences"
	quit
end tell
Click File->Save As. Name the file "mousePlugged" and save it anywhere where you won't accidentally move/delete it. I chose my Library Folder.
capturedcran20120302201.png
At this point, if you did everything correctly, you could click the "Run" button in the AppleScript Editor and it should automatically open your System Preferences, disable natural scrolling and close System Preferences all in a fraction of second.

Now you will need to create another AppleScript with this code:
Code:
tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.trackpad"
end tell

tell application "System Events"
	tell application process "System Preferences"
		tell tab group 1 of window "Trackpad"
			click radio button 2
			if value of checkbox 1 is 0 then
				click checkbox 1
			end if
		end tell
	end tell
end tell

tell application "System Preferences"
	quit
end tell
Save this one as "mouseUnplugged" at the same location as your last script. If you run it, it should automatically enable natural scrolling.


Step 3 : Installing and configuring MarcoPolo


MarcoPolo is a freeware that will allow to detect whenever a mouse is plugged or unplugged in order to automatically run the AppleScripts we just made when necessary.

Download MarcoPolo from its official website by scrolling and clicking on "MarcoPolo-2.5.dmg (Universal Binary)".
Install it by dragging it in your /Applications folder.
Open it and an its icon should appear in your menu bar. Click on it and select "Preferences...".

step3t.png

Go in the "Contexts" tab and add two contexts named "Mouse is plugged" and "Mouse is unplugged" respectively. Delete the default "Automatic" context.

step4a.png

Go in the "Rules" tab and add a USB Rule. Select "Apple Internal Keyboard / Trackpad [Apple, Inc.]", choose the context "Mouse is unplugged", set the confidence at 100% and click OK.

Next, add another rule (either USB or Bluetooth depending on your mouse) for the presence of your mouse. Make sure your mouse is connected when you do this step and select it in the list, then choose the context "Mouse is plugged", set the confidence at 100% and click OK. If you have multiple mice (home, work, etc.), add separate rules for each.
capturedcran20120302204.png
Go in the "Actions" tab and add an Open action. It will prompt you for a file, go select your "mousePlugged" AppleScript created in Step 2 and click Open. Choose the context "Mouse is plugged".

Create a second Open action with your "mouseUnplugged" AppleScript with the context "Mouse is unplugged".
capturedcran20120302210.png
You can now close the MarcoPolo preferences. At this point, natural scrolling should be turned off every time you plug your mouse and turned on every time you unplug it.

Step 4 : Launching MarcoPolo on startup and hiding the menu bar icon

Go to System Preferences -> Users and Groups. Click the on the "Login Items" tab and click on the "+" sign. Locate MarcoPolo in your /Applications folder an click Add. Close System Preferences.

If you would like to hide the MarcoPolo icon from your menu bar, click on it and on "Preferences..." and check the "Hide from status bar" checkbox in the "General" tab. MarcoPolo will now be permanently hidden unless you go open in from your /Applications folder.

And that's it! MarcoPolo will now be 100% transparent and launch at startup. Natural scrolling will toggle automatically every time you plug/unplug your mouse without requiring any manual toggling.
 

pgiguere1

macrumors 68020
Original poster
May 28, 2009
2,167
1,200
Montreal, Canada
There are currently no checkbox to allow natural scrolling only with the Trackpad.

Toggling the option in the Trackpad tab of the System Preferences will also toggle the one in the Mouse tab.

The point of this is to not have to mess with System Preferences every single time you plug/unplug your mouse, which is something a lot of users do on a daily basis.

My solution is not easy, and it's a shame that Apple hasn't allowed us to that by default, but it's currently the only solution that is free and works permanently.
 

Sylon

macrumors 68020
Feb 26, 2012
2,032
80
Michigan/Ohio, USA
Ohhhh, ok, I see what you are talking about now. Well, its still a lot of work for what comes down to only clicking a checkbox. I guess I don't connect/disconnect my mouse that often for it to bother me much.
 

ruedu

macrumors newbie
Jun 10, 2009
3
0
Call me biased but I think you should use ControlPlane over MarcoPolo - http://www.controlplaneapp.com/

I'm actually working on adding this functionality to ControlPlane directly, no AppleScript, but I'm having an issue convincing the system that the setting has changed.
 
Last edited:

ClawKing

macrumors newbie
Apr 8, 2012
6
1
When my mouse is plugged in, it still says mouse unplugged, and when i force it to "mouse plugged" it says opening script failure, any suggestions?
 

ClawKing

macrumors newbie
Apr 8, 2012
6
1
Update on my problem -
I've narrowed it down the the applescript, as it open system preferences, goes to the correct preference pane, but no more, that's when it fails. when i attempt to run the script straight from applescript, the line "tell tab group 1 of window "Trackpad"" is incorrect/unrecognised, as the following error message comes up:
 

Attachments

  • A Snapshot of my Macbook 2012-04-09 at 11.09.34.png
    A Snapshot of my Macbook 2012-04-09 at 11.09.34.png
    99.8 KB · Views: 213

phatskat

macrumors newbie
Apr 10, 2012
4
0
I updated your original script to do a couple of things differently:
- System Preferences doesn't "activate" - keeping it in the background
- Added a Growl Notification so that if you have Growl and the helper is running, you'll see a "Natural Scroll Disabled/Enabled" alert.
- The script toggles instead of having two scripts - so if it's enabled, this will disable it, and vice versa.

I'm sure this could be improved as I'm not an AppleScript expert, and most of the Growl code was borrowed from a sample script. Just save this script and run it when you need a change. I think, for example, that I can activate this with my Logitech mouse on one of the auxiliary buttons. I'm also going to look for a way to invoke it with a keyboard shortcut.

Code:
-- Growl check
tell application "System Events"
	set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell

tell application "System Preferences"
	set current pane to pane "com.apple.preference.trackpad"
end tell

tell application "System Events"
	tell application process "System Preferences"
		tell tab group 1 of window "Trackpad"
			click radio button 2
			click checkbox 1
			set isEnabled to value of checkbox 1
		end tell
	end tell
end tell

tell application "System Preferences"
	quit
end tell

if isRunning then
	tell application id "com.Growl.GrowlHelperApp"
		set the allNotificationsList to {"Enabling Natural Scroll", "Disabling Natural Scroll"}
		set the enabledNotificationList to {"Enabling Natural Scroll", "Disabling Natural Scroll"}
		
		register as application "Growl Alert for Natural Scroll" all notifications allNotificationsList default notifications enabledNotificationList icon of application "Script Editor"
		
		if isEnabled = 1 then
			notify with name "Enabling Natural Scroll" title "Natural scroll has been enabled" description "Natural Scroll Toggler" application name "Growl Alert for Natural Scroll"
		else
			notify with name "Disabling Natural Scroll" title "Natural scroll has been disabled" description "Natural Scroll Toggler" application name "Growl Alert for Natural Scroll"
		end if
	end tell
end if
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.