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 no translation for that post!




Share:
Notifications
Clear all

Lazarus - macOS - How to read macOS preferences

1 Posts
1 Users
0 Likes
1,808 Views
 Hans
(@hans)
Famed Member Admin
Joined: 10 years ago
Posts: 2554
Topic starter  

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

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: