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!
[Solved] Lazarus - MacOS X - How to detect "Dark" theme on your Mac
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2822
Topic starter
September 11, 2015 9:34 PM
Some people like to use the so called "Dark theme" on their Mac ("System Preferences" -> "General" -> Check "Use dark menu bar and dock"), which comes with a nice look ...
Sometimes you'd like to be able to detect if this dark theme has been enabled, for example to select a suitable icon in TTrayIcon.
With a little trick I've managed to get that going.
Add "Process" to your Uses clause.
This function returns TRUE when the Dark Theme has been enabled, or FALSE when it's the default theme.
function TForm1.DetectDarkTheme:boolean;
var s:ansistring;
begin
RunCommand('/usr/bin/defaults',['read','-g','AppleInterfaceStyle'],s);
DetectDarkTheme:=(pos('Dark',s)>0);
end;