How to return current NSScrollerStyle

Hi everyone,

in the system settings of macOS you can set options for the scrollbars in the tab “General”. There are three options:

  1. automatically based on mouse and trackpad
  2. when scrolling
  3. always

How can I read the current setting from a Xojo program? Is there a declare for that? I’m not that fit into Declarations, but found this:

Best regards

Thanks to my friend @Ulrich Bogun

[code]#If TargetMacOS
Const legacy = 0
Const overlay = 1

Declare Function NSClassFromString Lib “Cocoa” (classname As CFStringRef) As Ptr
Declare Function getPreferredScrollerStyle Lib “Appkit” Selector “preferredScrollerStyle” (ScrollerId As Ptr) As Integer

Select Case getPreferredscrollerStyle(NSClassFromString(“NSScroller”))
Case legacy
MsgBox(“Specifies legacy-style scrollers as prior to macOS 10.7+.”)
Case overlay
MsgBox(“Specifies overlay-style scrollers in macOS 10.7+.”)
End Select
#EndIf[/code]

Glad you were able to get it worked out! I was just about to reply with basically the same.

[quote=370429:@Martin T]Thanks to my friend @Ulrich Bogun

[code]#If TargetMacOS
Const legacy = 0
Const overlay = 1

Declare Function NSClassFromString Lib “Cocoa” (classname As CFStringRef) As Ptr
Declare Function getPreferredScrollerStyle Lib “Appkit” Selector “preferredScrollerStyle” (ScrollerId As Ptr) As Integer

Select Case getPreferredscrollerStyle(NSClassFromString(“NSScroller”))
Case legacy
MsgBox(“Specifies legacy-style scrollers as prior to macOS 10.7+.”)
Case overlay
MsgBox(“Specifies overlay-style scrollers in macOS 10.7+.”)
End Select
#EndIf[/code][/quote]

where event should i put this code in?? i assume the Open_event

You can call it whenever you want. App.Open-Event, PushButton.Action etc. It will repeat always the Integer-Value of the current system attitude. Also if you change this preference during the runtime in your macOS preferences.

I have to ask, what are you planning to do; now you have that information?

window.activate would be my best guess, that way your app will re-read that setting when the user activates the window, especially after they’ve been to the system preferences and back.