Add a command to keepassxc-cli that will lock databases of running keepassxc instances.
Invoking keepassxc-cli lock (or similar) will lock all running instances of keepassxc of the user invoking the command.
I want to write scripts that lock the database when certain conditions occur. For example when suspending the machine, or when locking the screen (the auto-locking when locking the desktop doesn't seem to work under wayland), or even when the signal of the bluetooth connection to my cellphone gets too weak, indicating I moved away from my machine.
The cli and the desktop app have no communication between each other. I prefer to keep it that way. The proper way to do this is to add the --lock command to keepassxc itself. Single instance will handle the lock message.
I was not aware of the non-communication part, as long as it's possible for me to lock the database non-interactively I'd be fine with whatever alternative works best for the project :)
If you're able to use dbus, you can use this command per the Using DBus with KeePassXC wiki page:
qdbus org.keepassxc.KeePassXC.MainWindow /keepassxc org.keepassxc.KeePassXC.MainWindow.lockAllDatabases
I'll have a look into that, at first glance that would be sufficient for my purposes. Thanks!
If you're able to use dbus, you can use this command per the Using DBus with KeePassXC wiki page:
qdbus org.keepassxc.KeePassXC.MainWindow /keepassxc org.keepassxc.KeePassXC.MainWindow.lockAllDatabases
The object name is not the same as the service name. Command should be
qdbus org.keepassxc.KeePassXC.MainWindow /keepassxc org.keepassxc.MainWindow.lockAllDatabases

Most helpful comment
The object name is not the same as the service name. Command should be