{"id":49954,"date":"2025-11-08T15:58:50","date_gmt":"2025-11-08T15:58:50","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=49954"},"modified":"2025-11-08T15:58:50","modified_gmt":"2025-11-08T15:58:50","slug":"custom-actions-switch-light-dark","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2025\/11\/custom-actions-switch-light-dark\/","title":{"rendered":"Run Custom Actions Automatically When Switch to Light or Dark"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-49955\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-icon-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/p>\n<p>Want to do some actions automatically when you switch desktop theme to light or dark style? Here&#8217;s a new application can do the job for GNOME Desktop.<\/p>\n<p>It&#8217;s <a href=\"https:\/\/github.com\/kem-a\/switchcraft\" target=\"_blank\" rel=\"noopener\">switchcraft<\/a>, a free open-source Vala written application that provides a modern simple interface, allowing to add custom commands to run automatically when the theme changes.<\/p>\n<p><!--more--><\/p>\n<p>The app monitors the <code>org.gnome.desktop.interface color-scheme<\/code> key value and executes commands instantly when it&#8217;s changed to &#8220;prefer-dark&#8221; or &#8220;prefer-light&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-49956\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-light-700x512.webp\" alt=\"\" width=\"610\" height=\"446\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-light-700x512.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-light-300x219.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-light-768x562.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/switchcraft-light.webp 931w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>It can be useful for doing the following things automatically when switching desktop between light and dark style:<\/p>\n<ul>\n<li>Change the legacy GTK3 theme, though Ubuntu already does it automatically.<\/li>\n<li>Change Qt app theme.<\/li>\n<li>Enable\/Disable extensions, or configure extensions&#8217; preferences.<\/li>\n<li>Change Gnome Shell theme.<\/li>\n<li>Or do whatever that you want.<\/li>\n<\/ul>\n<p>Simply add your desired commands in the &#8220;Light&#8221; and &#8220;Dark&#8221; tabs, and turn on &#8220;<b>Enable Monitor<\/b>&#8221; option in <i>Preferences<\/i>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-49958\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/start-monitoring-700x351.webp\" alt=\"\" width=\"610\" height=\"306\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/start-monitoring-700x351.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/start-monitoring-300x150.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/start-monitoring-768x385.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/start-monitoring.webp 1268w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>Then, it will auto-run the <code>switchcraft-monitor.sh<\/code> script under <code>.local\/bin<\/code> folder in next login, monitoring your desktop color scheme and running the commands automatically.<\/p>\n<p>Besides that, it supports adding reusable constants for common variables in commands. And, it support exporting all the commands and importing to other systems.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/constants.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-49959\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/constants-700x409.webp\" alt=\"\" width=\"610\" height=\"356\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/constants-700x409.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/constants-300x175.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/constants-768x449.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/constants.webp 1065w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<h3>Install switchcraft<\/h3>\n<p>Switchcraft provides official installer packages which are available to download in the link below:<\/p>\n<div class=\"wp-block-buttons aligncenter\">\n<div class=\"wp-block-button is-style-fill\"><a class=\"wp-block-button__link has-vivid-cyan-blue-to-vivid-purple-gradient-background has-text-color has-background\" href=\"https:\/\/github.com\/kem-a\/switchcraft\/releases\" target=\"_blank\" rel=\"noreferrer noopener\">Download Switchcraft (under &#8220;Assets&#8221;)<\/a><\/div>\n<\/div>\n<p>They include <code>.rpm<\/code> package for Fedora\/RHEL and <code>.deb<\/code> package for Debian\/Ubuntu, which can be installed by system software app (e.g., Gnome Software and App Center).<\/p>\n<p>For other Linux, it also provides non-install <code>AppImage<\/code> package that can be run directly to launch to the app, though you need to add executable permission from file properties dialog.<\/p>\n<p><b>NOTE:<\/b> switchcraft requires GNOME 40+, GLib &gt;= 2.66, and <code>jq<\/code> command-line JSON processor.<\/p>\n<h3>Example Commands:<\/h3>\n<p>For those who are new to Linux, here are some example commands that may help.<\/p>\n<p><b>1. change legacy GTK3\/Icon theme<\/b><\/p>\n<p><b>NOTE:<\/b> The commands are written for Debian, Fedora, etc Linux Distributions, as Ubuntu automatically set Yaru and its variants as legacy GTK3 theme.<\/p>\n<pre>gsettings set org.gnome.desktop.interface gtk-theme 'adw-gtk3-dark'<\/pre>\n<p>This command changes the GTK3 theme to <a href=\"https:\/\/github.com\/lassekongo83\/adw-gtk3\" target=\"_blank\" rel=\"noopener\">adw-gtk3<\/a> dark mode. You need to replace <code>adw-gtk3-dark<\/code> depends on which theme you want to set.<\/p>\n<pre>gsettings set org.gnome.desktop.interface icon-theme 'MacTahoe-light'<\/pre>\n<p>This will change the icon theme to <code>MacTahoe-light<\/code>. Also you need to change the theme name accordingly.<\/p>\n<p>Go to <a href=\"https:\/\/www.gnome-look.org\/browse?cat=135&amp;ord=latest\" target=\"_blank\" rel=\"noopener\">gnome-look.org<\/a> for more themes, and use &#8220;Gnome Tweaks -&gt; Appearance&#8221; to see all available choices.<\/p>\n<p><b>2. Enable\/Disable Extensions<\/b><\/p>\n<p>First, run command to list all the installed extensions.<\/p>\n<pre>gnome-extensions list<\/pre>\n<p>Then, disable an extension by command:<\/p>\n<pre>gnome-extensions disable ubuntu-dock@ubuntu.com<\/pre>\n<p>Here replace <code>disable<\/code> with <code>enable<\/code> if you want to enable an extension. And, replace extension ID <code>ubuntu-dock@ubuntu.com<\/code> accordingly.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-49960\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/disable-ext-700x408.webp\" alt=\"\" width=\"610\" height=\"356\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/disable-ext-700x408.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/disable-ext-300x175.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/disable-ext.webp 706w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><b>3. Configure Extension<\/b><\/p>\n<p>For system default extensions, use similar command below to configure:<\/p>\n<pre>gsettings set org.gnome.shell.extensions.dash-to-dock background-color \"#ffffff\"<\/pre>\n<p>You may install and use the graphical &#8220;Dconf Editor&#8221; tool to get available extension names, keys, and key values.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-49961\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gsettings-dash2dock-background-700x405.webp\" alt=\"\" width=\"610\" height=\"353\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gsettings-dash2dock-background-700x405.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gsettings-dash2dock-background-300x174.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gsettings-dash2dock-background-768x444.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gsettings-dash2dock-background.webp 890w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>For user installed extensions, you may first run command to list them:<\/p>\n<pre>gnome-extensions list --user --enabled<\/pre>\n<p>Then, print metadata of an extension (User Themes for example), to get the setting schema:<\/p>\n<pre>cat $HOME\/.local\/share\/gnome-shell\/extensions\/user-theme\\@gnome-shell-extensions.gcampax.github.com\/metadata.json<\/pre>\n<p>Next, set constants:<\/p>\n<pre>THEME_SCHAMA=org.gnome.shell.extensions.user-theme\r\nTHEME_SCHAMADIR=$HOME\/.local\/share\/gnome-shell\/extensions\/user-theme\\@gnome-shell-extensions.gcampax.github.com\/metadata.json\/schemas<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gnome-extensions-metadata.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-49962\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gnome-extensions-metadata-700x499.webp\" alt=\"\" width=\"610\" height=\"435\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gnome-extensions-metadata-700x499.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gnome-extensions-metadata-300x214.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gnome-extensions-metadata-768x547.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2025\/11\/gnome-extensions-metadata.webp 874w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/a><\/p>\n<p>Finally, run command to configure the &#8220;name&#8221; (get the key from &#8216;gschema.xml&#8217; file in extension folder) for the extension.<\/p>\n<pre>gsettings --schemadir $THEME_SCHEMADIR set $THEME_SCHEMA name \"ChromeOS-dark-compact-shell\"<\/pre>\n<p>Feel free to leave command below if you want more commands.<\/p>","protected":false},"excerpt":{"rendered":"<p>Want to do some actions automatically when you switch desktop theme to light or dark style? Here&#8217;s a new application can do the job for GNOME Desktop. It&#8217;s switchcraft, a free open-source Vala written application that provides a modern simple interface, allowing to add custom commands to run automatically when the theme changes.<\/p>\n","protected":false},"author":1,"featured_media":49955,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[689],"class_list":["post-49954","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-gnome"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/49954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=49954"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/49954\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/49955"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=49954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=49954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=49954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}