Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!





Share:
Notifications
Clear all

Lazarus - macOS - How to read macOS preferences  

  RSS

 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 870
November 21, 2020 5:54 AM  

Sometimes we'd like to read the system preferences, so we can use the information to have our application respond to it.

A great resource, which appears to hard to find at times, is Lazarus Wiki - Mac Preferences Read and Write page which shows you how to use this to store your own preferences and my purpose was reading system settings/preferences. At least this got me started with a simple solution to read system settings, even the not so standard ones.

In my situation I wanted to read the "reduceTransparency" setting, which is found in "com.apple.universalaccess" (file: ~/Library/Preferences/com.apple.universalaccess).

First fo all, your application needs to use the units MacOSAll and CFPreferences;

  uses MacOSAll, CFPreferences;

Note: CFPreferences is not needed if your project already uses CocoaAll.

Next we need two variables, one as a status value (key exists) and one depending on the returning datatype:

var
IsValid: Boolean; // On return indicates if key exists and has valid data
Pref: Integer;

Reading the value then becomes relatively easy:

Pref := CFPreferencesGetAppIntegerValue(CFStr('reduceTransparency'),CFSTR('com.apple.universalaccess'),IsValid);

Note: if the key value does not exist, expect IsValid to be FALSE.

Note: for different datatypes you'll also find:

CFPreferencesGetAppIntegerValue
CFPreferencesGetAppBooleanValue

Using strings and arrays will be a little more challenging.


ReplyQuote
Share: