How do I change the color scheme from the command line

I use darkman to transition my development environment between night mode and day mode automatically. (i.e. It automates toggling between light themes and dark themes in my applications twice per day.)

It seems the theme configuration for Inkdrop is stored in ~/.config/inkdrop/config.cson. I’ve tried to modify this file and change the theme name, but unfortunately Inkdrop doesn’t seem to reload when the config file is changed.

Is it possible to change themes in Inkdrop at runtime, without doing so manually through the settings panel?


As a further improvement, there is now a standardized interface for detecting the system-wide color scheme preference. Applications can subscribe to this D-bus interface to automatically switch between light and dark themes, much like they’ve been able to do in Windows and MacOS for years.

This interface is already implemented in Gnome and KDE (and darkman), It’s currently being used by Firefox (that I know of), and there are tickets open for adding support to Chromium, Sublime Text Telegram and probably many more.

Environment

  • Platform: Arch Linux
  • Platform version: rolling
  • App Version: 5.5.1

Hi Tomas,

I guess updating config.cson should just work, no?
If I update the *.core.themes value manually, the app automatically updates the themes immediately without relaunching.

1 Like

This doesn’t work for me, I just tested it again to make sure. Perhaps it’s a platform difference, I’m on Linux. Are you on MacOS?

Oh, interesting… I just tried using sed instead of using Vim, and now it works. I guess it’s because Vim by default moves the original file and saves a new file with the same name. If Inkdrop is only watching an inode then it wouldn’t realize the file was updated.

Apologies for wasting your time! :sweat_smile:

Success!

Turns out sed didn’t work properly either, it picked up the first change, then it stopped working. Apparently sed also does some weird stuff with creating a new file and copying it over the original file, breaking the inode watch. Relatively simple to work around though, I just needed to work on a copy of the config, then writing it over the original file. I now have a working darkman light/dark mode script for Inkdrop! :tada:

#!/bin/bash

[[ $0 == *dark-mode.d* ]] && MODE="dark" || MODE="light"

DARK_UI="vibrant-dark-ui"
DARK_SYNTAX="energy-syntax"
LIGHT_UI="default-light-ui"
LIGHT_SYNTAX="twilight-light-syntax"

CONFIG_PATH="$HOME/.config/inkdrop/config.cson"

if [[ ! -f "$CONFIG_PATH" ]]; then
    echo "Inkdrop config file not found, skipping ($CONFIG_PATH)"
    exit 0
fi

# Any config changes are made in a temporary copy of the config file, since
# modifying it inline (sed -i) would break the inode watch Inkdrop has on the
# file.

BUF="$(mktemp)"
trap "rm $BUF" EXIT

cat "$CONFIG_PATH" > "$BUF"

if [[ "$MODE" = "light" ]]; then
    CHOSEN_UI=$LIGHT_UI
    CHOSEN_SYNTAX=$LIGHT_SYNTAX
else
    CHOSEN_UI=$DARK_UI
    CHOSEN_SYNTAX=$DARK_SYNTAX
fi

sed -i -r "s/\"[^\"]+-ui\"/\"$CHOSEN_UI\"/" "$BUF"
sed -i -r "s/\"[^\"]+-syntax\"/\"$CHOSEN_SYNTAX\"/" "$BUF"

cat "$BUF" > "$CONFIG_PATH"

Video demo: Demo of Inkdrop dark/light mode toggle with Darkman

1 Like

FYI: Inkdrop uses pathwatcher to watch the config file.

Congrats🎉

1 Like