Automate the process whenever a new wallpaper is set
los2pollos opened this issue · 18 comments
Hi, I'm using Cinnamon. I'd like to automate the process. The workflow should be something like this:
- A new wallpaper is set (either manually or with an automatic slideshow)
- wal-telegram creates a new palette and config file
- The config file is automatically loaded in the Telegram client
I was trying to explore the solution provided in #11 but I could not understand it.
In particular, I was not able to understand if it addresses the issue I'm bringing right now, or if it is even possible.
P.S. Nice project! It needs to be better documented since it is directly referenced in a much larger one
Hi, so to address your points one by one but not in order :
- 3 is already the case, telegram just doesn't do live updates and I can't find a way to force a reload of the interface. But restarting telegram makes it use the newly generated palette, although I suppose I could add an option to kill and restart telegram.
- 1 would be quite complicated I think, this would mean implementing the behavior for all possible DE which doesn't sound great in my opinion ^^ But that's open to discussion I suppose, there might be some elegant way to do this. So the solution right now is to "plug" a script running wal-telegram to whatever sets the background on your DE (On a more custom desktop you'd probably have something like bspmwrc or i3/config where you'd put your script to run)
- And 2 is quite related to 1 at this stage, as I said above you would have wal-telegram run alongside whatever program sets your background or, if it is not possible, have some cron job or something running in the background to run wal-telegram with the current background every so often.
I don't know anything about cinnamon and it's inner workings. You could try to find out if there is a setting somewhere to run a command when the wallpaper changes, you could install a different wallpaper program (although that's not ideal I know). Or you could have a cron job running every couple minutes to run wal-telegram with the current background. apparently it is available with gsettings : https://unix.stackexchange.com/questions/59653/change-desktop-wallpaper-from-terminal
The program is really meant to work with wal, and the way wal sets the background. So event though I try to put some options on it, I feel like it's somewhat expected to have to tinker a bit to get it to work with something else.
I hope that helps you a little, I'd be glad to help you further with the tinkering if you need any help or feel free to close this issue.
Hi there, thank you so much for your reply!
I'm just not an expert of different DE, I only know about my current Cinnamon setup (see my repos for more info).
For the first point, I'm currently using Variety for setting wallpapers automatically. A script should do something like this (taken from my .bashrc):
#---PyWal---#
# load previous theme: this allows for persistence over rebooting
(cat ~/.cache/wal/sequences &)
# get picture path
picturepath=$(gsettings get org.gnome.desktop.background picture-uri)
# remove prefix & suffix
prefix="'file://"
suffix="'"
picturepath=${picturepath#"$prefix"}
picturepath=${picturepath%"$suffix"}
# set colors
wal -n -q -i "$picturepath"
#---PyWal End---#
wal-telegram
I suppose that in this specific case, since Cinnamon is based on GNOME, the block with the $picturepath
variable should be the core of a script for automating other elements, such as wal-telegram. I guess that variable addresses your 2nd point.
However, since I implemented this scripting in the .bashrc file, the easiest case occurs when the user log in. The sequence in which the changes occur is important. The point is to maybe, as you were suggesting, run a cronjob that runs wal-telegram every now and then and if something changes, it kills the client: not elegant but may do the trick.
Ideas?
Yep that is pretty much exactly what I have on my setup, a script that sets a random background and runs wal and all wal related software. It runs on startup, and whenever I change the wallpaper manually I do it through this script.
From what I found variety uses some configs, and it appears you can modify the script used when variety runs (in ~/.config/variety). Chances are you can probably make your wal script run from there ? https://peterlevi.com/variety/comment-page-13/#comment-93835 and comments around that gave the idea.
Yes! I've edited the following file: ~/.config/variety/scripts/set_wallpaper
gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
if [ "$(gsettings get org.gnome.desktop.background picture-options)" == "'none'" ]; then
gsettings set org.gnome.desktop.background picture-options 'zoom'
# Import colorscheme from 'wal' asynchronously
# & # Run the process in the background.
# ( ) # Hide shell job control messages.
# Not supported in the "fish" shell.
(cat ~/.cache/wal/sequences &)
# Alternative (blocks terminal for 0-3ms)
cat ~/.cache/wal/sequences
# To add support for TTYs this line can be optionally added.
source ~/.cache/wal/colors-tty.sh
wal -n -q -i "$1"
pywalfox update
wal-telegram -w
pkill telegram-desktop
telegram-desktop
fi
As explained at the beginning of the file: "$1: The first passed parameter is the absolute path to the wallpaper image to be set as wallpaper". Terminals and firefox update instantly, whereas telegram is a bit inconsistent.
First of all, I have to manually kill the process EVERY single time, killing from the bash does not work.
Also, it seems that the theme file in ~/.cache/wal-telegram sometimes does not get generated correctly.
I need more help in troubleshooting.
Do you mean the pkill doesn't work in the script ? That's odd. I guess a restart option in wal-telegram seems reasonable so I might do that.
As for the theme not generating I'd need a little bit more info, ideally a reproducible context or something. You could also make sure the theme was indeed not regenerated by doing a cmp on the previous and the new file, or comparing their md5sum if you don't want to copy the previous theme.
I'm checking md5sums with 'md5sum -b wal.tdesktop-theme' and the file gets actually generated by the terminal. It get also generated by the .bashrc
The problem seems to be in the Variety script 'set_wallpaper'. I've isolated single functions, and none of them work in the set wallpaper script. It is not working but I don't know why. In fact, all the changes that I experienced so far are coming straight from .bashrc, not from the Variety script.
I'm checking md5sums with 'md5sum -b wal.tdesktop-theme' and the file gets actually generated by the terminal. It get also generated by the .bashrc
The problem seems to be in the Variety script 'set_wallpaper'. I've isolated single functions, and none of them work in the set wallpaper script. It is not working but I don't know why. In fact, all the changes that I experienced so far are coming straight from .bashrc, not from the Variety script.
I think the problem is the killing telegram with "pkill telegram-desktop"
for me only "pkill telegram-deskto" works, without the 'p'.Must be a typo by tg devs.
I'm on arch btw,
You could try to make sure that the set_wallpaper script in .config is indeed called on the variety runs, like jamming an output to a tmp file in or something. I guess it is possible that some other script somewhere else is getting called instead.
If the script is not being called I'd suggest you to turn to the variety team, if it is being called however maybe check that your piece of code is correct, for example I doubt (shot in the dark) that you'd have to use the if clause with the picture options. To me this would make your code run at most only once on first call of set_wallpaper and never afterwards.
I'd also recommend to put all your code related to wal in a little script so that it is more convenient to make modifications. Oh hello good timing ^^
I think the problem is the killing telegram with "pkill telegram-desktop"
for me only "pkill telegram-deskto" works, without the 'p'.Must be a typo by tg devs.
I'm on arch btw,
Oh you're not OP xD I think executable names get cropped after some length you'd have to use pkill -f to match the full command line I believe.
You could try to make sure that the set_wallpaper script in .config is indeed called on the variety runs, like jamming an output to a tmp file in or something. I guess it is possible that some other script somewhere else is getting called instead. If the script is not being called I'd suggest you to turn to the variety team, if it is being called however maybe check that your piece of code is correct, for example I doubt (shot in the dark) that you'd have to use the if clause with the picture options. To me this would make your code run at most only once on first call of set_wallpaper and never afterwards. I'd also recommend to put all your code related to wal in a little script so that it is more convenient to make modifications. Oh hello good timing ^^
Thank you for the help, very good suggestions.
What do you mean with "jamming an output to a tmp file"? I'm not an expert in bash
I think executable names get cropped after some length you'd have to use pkill -f to match the full command line I believe.
I indeed already explored this and I confirm your assumptions
Lastly, another point to consider is that there are the same folders and files both in ~/.config/variety and in /usr/share/variety. What do you think is the difference? I tried to edit both, but nothing changed
What do you mean with "jamming an output to a tmp file"? I'm not an expert in bash
You can put something like echo "running" >> /tmp/variety.log
anywhere in the set_wallpaper script, or well outside any clauses I suppose, so before the gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
line should do for example.
Then check the /tmp/variety.log file if it exists and has as many running
as the number of times variety ran it means the script is called.
Lastly, another point to consider is that there are the same folders and files both in ~/.config/variety and in /usr/share/variety. What do you think is the difference? I tried to edit both, but nothing changed
Yeah so that could be part of the problem, usually configs in /usr/share/ are default configs in case no config is set in ~/.config/, at least from my understanding ^^ I hope I'm not saying crap. But it should use ~/.config in priority. You can try the test I just mentioned in the config of /usr/share if the one in ~/.config doesn't seem to run.
Thank you so much for your help so far. I'm getting closer and closer. Basically it is indeed enough to tinker with those two script files and make them execute a third sh script (I called it custom.sh)
Anyway, regarding wal-telegram, I keep getting this from the telegram client:
(telegram-desktop:160058): Gtk-WARNING **: 21:13:34.504: Locale not supported by C library.
Using the fallback 'C' locale.
[E] pw.loop [loop.c:86 pw_loop_new()] 0x7f62c3565870: can't make support.system handle: No such file or directory
[ALSOFT] (EE) Failed to create PipeWire event thread loop (errno: 2)
/usr/share/libdrm/amdgpu.ids: No such file or directory
error: : cannot open
error: : cannot open
error: : cannot open
qt.svg: Error while inflating gzip file: SVG format check failed
What is this? The theme is not getting applied
Thank you so much for your help so far. I'm getting closer and closer. Basically it is indeed enough to tinker with those two script files and make them execute a third sh script (I called it custom.sh)
I really don't think it is necessary to modify both of them, only one should do it I just don't know which one. This would avoid you to have duplication that can become a bit of a headache.
Anyway, regarding wal-telegram, I keep getting this from the telegram client:
I am not too sure, I hope it isn't some problem with pipewire because I have no idea how it works. I see there is some output about svg though, is your wallpaper an svg ? Because I am pretty sure this is not supported, if it is the case try with a png background to see if it works. I am actually going to make the program convert any wallpaper to png for the theme so this won't be a problem.
EDIT: SVG should work on the newer version and I added the -r option for restarting telegram
Also I opened an issue on tdesktop for the interface reload problem: telegramdesktop/tdesktop#24675
You can go react to it if you want, it might slightly push up the priority.
Hey, for anyone out there looking for the same answer: in order to seamlessly automate the adjusting of colors, only a few files must be edited.
- Create your custom script under
~/.config/variety/scripts/
. Make sure it is an executable bash file withchmod +x
- Reference your custom script in
get_wallpaper
. This will make sure that the first time that variety is launched, the custom script will be launched as well. - Edit
/usr/lib/python3/dist-packages/variety/VarietyWindow.py
at line 1466. Put someos.system('bash ~/.config/variety/scripts/custom.sh')
. This will run your custom script whenever a new wallpaper is set. Basically there are two functions:set_wallpaper()
anddo_set_wp()
. The first one just calls the scriptset_wallpaper
in the script folder, but it is actually the second one that effectively applies the changes. Unfortunately, theset_wallpaper
script only applies AFTER the wallpaper is set. I haven't really figured out its purpose, but referencing the custom script in this file will only get delayed effects and the palette generated by wal is based on the previous wallpaper changed.
SVG should work on the newer version and I added the -r option for restarting telegram
Great! I'll test it out right away.
Also I opened an issue on tdesktop for the interface reload problem: telegramdesktop/tdesktop#24675 You can go react to it if you want, it might slightly push up the priority.
Sounds good!
We can close the issue as soon as the new telegram-desktop snap package is released. Thx
The autoreload feature made it to https://github.com/telegramdesktop/tdesktop/releases/tag/v4.0.1, closing the issue.