Skip to content

Instantly share code, notes, and snippets.

@quienn
Last active January 19, 2022 00:07
Show Gist options
  • Save quienn/244db25dbccd5999ea4ec85655574782 to your computer and use it in GitHub Desktop.
Save quienn/244db25dbccd5999ea4ec85655574782 to your computer and use it in GitHub Desktop.
elementary OS Flatpak Theme Changer
--- Run this script using a cronjob. I'm running this according to my elementary OS settings:
--- From 06:00 AM (light theme) to 09:00 PM (dark theme) Mexico City Timezone
exec = (command, ...) ->
io.popen "#{command} #{table.concat (table.pack ...), ' '}"
FLATHUB_APPS = {}
local COLOR_SCHEME
local THEME
do
with exec "gsettings get org.freedesktop prefers-color-scheme"
COLOR_SCHEME = ((\read "*a")\gsub "'(.-)'", "%1")\gsub "%s", ""
\close!
with exec "gsettings get org.gnome.desktop.interface gtk-theme"
THEME = ((\read "*a")\gsub "'(.-)'", "%1")\gsub "%s", ""
\close!
with exec "flatpak list --app --columns=application,origin"
for line in \lines!
application, origin = line\match "^([%w._-]+)%s*(%w+)%s*$"
if origin != "appcenter"
table.insert FLATHUB_APPS, application
\close!
SYSTEM_THEME = if COLOR_SCHEME == "dark" then "#{THEME}-dark" else THEME
--- Do the actual thing
for app_id in *FLATHUB_APPS
with exec "flatpak override --user --env=GTK_THEME=#{SYSTEM_THEME} #{app_id}"
\close!
@quienn
Copy link
Author

quienn commented Jan 19, 2022

Update: No need for this as elementary joined forces with major DEs out there (KDE, GNOME) to make the Freedesktop Color Scheme preference a thing! Firefox 98 will surely support it, as well as most GNOME apps using libadwaita.

https://blogs.gnome.org/alexm/2021/10/04/dark-style-preference/
https://bugzilla.mozilla.org/show_bug.cgi?id=1734934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment