Archive for August 2011


Java: Checking which scrolling direction is enabled in Mac OS Lion

August 16th, 2011 — 8:08pm

With the introduce of Mac OS Lion Apple added the option to enable „natural scrolling“ which simply inverts the scrolling direction of input devices to get an iOS like scrolling behavior. However, some Apps may require to ‚invert the inverted scrolling‘, like Apps which use scrolling for zooming, which indeed should not be inverted. Unfortunately Apple dropped the development of Java and didn’t added a method or property to get the scrolling behaviour.

So today I tried to find a solution which helps to find out if natural scrolling is enabled or not in Java. I know that the preference would be saved in a .plist file so I checked with fseventer which one it was. After this the only thing I had to do was finding a library which allowed me to read .plist files and to check the scrolling property.

You will need this library to run the snippet.

try {
    File globalPref = new File(System.getProperty("user.home") + "/Library/Preferences/.GlobalPreferences.plist");
    NSDictionary dict = (NSDictionary)PropertyListParser.parse(globalPref);
 
    NSNumber pref = (NSNumber)dict.objectForKey("com.apple.swipescrolldirection");
 
    if(pref.boolValue()) {
        //natural scrolling is enabled
    }
 
 
} catch (Exception ex) {
    System.out.println("Faild to parse plist: " + ex.getMessage());
}

Hopefully this small snippet will be useful.

1 comment » | Digitale Welt, Java, Macintosh, Programmieren

Back to top